JVM有两种运行模式Server与Client。两种模式的区别在于,Client模式启动速度较快,Server模式启动较慢;但是启动进入稳定期长期运行之后Server模式的程序运行速度比Client要快很多。这是因为Server模式启动的JVM采用的是重量级的虚拟机,对程序采用了更多的优化;而Client模式启动的JVM采用的是轻量级的虚拟机。所以Server启动慢,但稳定后速度比Client远远要快。
一、当前是Client or Server
java -versinon
如下:
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
二、Client 与 Server 切换
2.1、模式配置文件
JVM启动时采用何种模式是在名为jvm.cfg的配置文件中配置的。
配置文件的位置:
32位的虚拟机在%JAVA_HOME%/jre/lib/i386/jvm.cfg
64位的虚拟机在%JAVA_HOME%/jre/lib/amd64/jvm.cfg
打开32位的虚拟机对应的模式配置文件:
# Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
# ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
# List of JVMs that can be used as an option to java, javac, etc.
# Order is important -- first in this list is the default JVM.
# NOTE that this both this file and its format are UNSUPPORTED and
# WILL GO AWAY in a future release.
# You may also select a JVM in an arbitrary location with the
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
# and may not be available in a future release.
-client KNOWN
-server KNOWN
第一行的模式 -client KNOWN 被作为虚拟机默认的运行模式,如果想让32位的虚拟机按照server模式运行,将第一行和第二行代码交换位置。
jvm.cfg中配置:(此时为client模式)
64位的虚拟机对应的模式匹配文件关于运行模式代码:
-server KNOWN
-client IGNORE
client模式后面对应的参数为 IGNORE。说明64位虚拟机的server模式无法转换成client模式。
64位只支持server模式。
jvm.cfg中配置:(此时为server模式)
评论