如何确保我使用的是“服务器" JVM? [英] How to make sure I'm using the "server" JVM?

查看:69
本文介绍了如何确保我使用的是“服务器" JVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sun的JVM有两种风格:-client-server,其中应该为长时间运行的进程优化服务器VM,并建议将其用于服务器应用程序.

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.

当我不带参数运行java时,它会显示用法选项,其中包括以下文本:

When I run java with no parameters, it displays the usage options, which includes the following text:


    The default VM is server,  
    because you are running on a server-class machine.

看到这一点后,我便开始将-server添加到流程启动命令中.

Having seen this, I didn't bother to add the -server to the process startup command.

但是,在最近的JVM崩溃日志中,我注意到文件末尾附近的以下行:

However, on a recent JVM crash log, I noticed the following line near the end of the file:


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)

在我看来,尽管Java在帮助消息中说了什么,但Java仍在使用客户端VM.我将在我的启动命令中添加-server选项,但是现在我很可疑.所以我的问题是:是否有一种方法可以确保我正在运行的VM确实是服务器VM,而不必诉诸于JVM崩溃?

It seems to me that Java is using the Client VM, despite what it says in the help message. I'm going to add the -server option to my startup command, but now I'm suspicious. 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?

该操作系统为ubuntu 8.04,但我使用的是从Sun网站下载的JDK 1.6.0_14.

The OS is ubuntu 8.04, but I'm using JDK 1.6.0_14 which I downloaded from Sun's website.

推荐答案

您可以

System.out.println(System.getProperty("java.vm.name"));

我的机器上哪个返回:

Java HotSpot(TM)客户端VM

Java HotSpot(TM) Client VM

Java HotSpot(TM)64位服务器VM

Java HotSpot(TM) 64-Bit Server VM

当然,您不应基于此值执行任何重要操作,因为该值将来可能会更改,并且在另一个JVM上将完全不同.

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆