[英]How to make sure I'm using the “server” JVM?
Sun's JVM comes in two flavors: -client
and -server
, where the Server VM is supposed to be optimized for long running processes, and is recommended for server applications. Sun的JVM有两种形式:
-client
和-server
,其中Server VM应该针对长时间运行的进程进行优化,建议用于服务器应用程序。
When I run java
with no parameters, it displays the usage options, which includes the following text: 当我运行没有参数的
java
时,它会显示用法选项,其中包括以下文本:
The default VM is server, because you are running on a server-class machine.
Having seen this, I didn't bother to add the -server
to the process startup command. 看过这个之后,我没有费心将
-server
添加到进程启动命令中。
However, on a recent JVM crash log, I noticed the following line near the end of the file: 但是,在最近的JVM崩溃日志中,我注意到文件末尾附近的以下行:
vm_info: Java HotSpot(TM) Client VM (14.0-b16) for linux-x86 JRE (1.6.0_14-b08), built on May 21 2009 02:01:47 by "java_re" with gcc 3.2.1-7a (J2SE release)
It seems to me that Java is using the Client VM, despite what it says in the help message. 在我看来,Java正在使用客户端虚拟机,尽管它在帮助消息中说明了这一点。 I'm going to add the
-server
option to my startup command, but now I'm suspicious. 我要在我的启动命令中添加
-server
选项,但现在我很怀疑。 So my question is: is there a way to make sure that the VM I'm running in is really the Server VM, without resorting to forcing a JVM crash? 所以我的问题是: 有没有办法确保我运行的虚拟机真的是服务器虚拟机,而不是强迫JVM崩溃?
The OS is ubuntu 8.04, but I'm using JDK 1.6.0_14 which I downloaded from Sun's website. 操作系统是ubuntu 8.04,但我使用的是从Sun网站下载的JDK 1.6.0_14。
You can do 你可以做
System.out.println(System.getProperty("java.vm.name"));
Which on my machine returns either: 我的机器上的哪一个返回:
Java HotSpot(TM) Client VM
Java HotSpot(TM)客户端VM
or 要么
Java HotSpot(TM) 64-Bit Server VM
Java HotSpot(TM)64位服务器VM
Of course you shouldn't do anything critical based on this value, as it will probably change in the future, and will be completely different on another JVM. 当然,你不应该根据这个值做任何关键的事情,因为它将来可能会改变,并且在另一个JVM上会完全不同。
I had a very similar question which I asked on ServerFault . 我在ServerFault上提出了一个非常类似的问题。 I would say, if you care which version is run, always use -client or -server.
我想说,如果你关心运行哪个版本,请始终使用-client或-server。
Well, if you explicitly start with the -server command line prompt, you are running in server mode. 好吧,如果您明确地从-server命令行提示开始,那么您正在服务器模式下运行。 You can check that with this:
你可以用这个来检查:
ManagementFactory.getRuntimeMXBean().getInputArguments();
You can look at RuntimeMXBean which may open up more information, but that would have to be tested on the specific JVM you are running. 您可以查看RuntimeMXBean ,它可能会打开更多信息,但必须在您运行的特定JVM上进行测试。
Without writing any single line of code, if you use JConsole to connect to your JVM, under 'VM Summary' tab, it should say exactly which (server or client) Virtual Machine is being monitored. 如果您不使用任何单行代码,如果使用JConsole连接到JVM,则在“VM Summary”选项卡下,应该确切地说明正在监视哪个(服务器或客户端)虚拟机。
For example, 例如,
Virtual Machine: OpenJDK Server VM version 1.6.0-b09
To remotely monitor your JVM using JConsole, simply enable the JMX (Java Management Extensions) agent by starting JVM with the following System Properties 要使用JConsole远程监视JVM,只需通过使用以下系统属性启动JVM来启用JMX(Java Management Extensions)代理
> java.rmi.server.hostname=[your server IP/Name] // without this, on linux, jconsole will fail to connect to the remote server where JVM is running
> com.sun.management.jmxremote.authenticate=false
> com.sun.management.jmxremote.ssl=false
> com.sun.management.jmxremote.port=[portNum]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.