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 模式)
评论