简体   繁体   English

如何确保我使用“服务器”JVM?

[英]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.

相关问题 我不确定如何使此堆栈实现动态 - I'm not sure how to make this stack implementation dynamic 如何确保JVM中只有一个类实例? - How to make sure that there is just one instance of class in JVM? 如何确保每个 jvm 有一个 guava 服务管理器实例? - how to make sure single guava service manager instance per jvm? 不确定我在java中正在使用方法:/ - Not sure I'm using methods right in java :/ 我不确定如何在小三角形上添加空格以使其变为大三角形 - I'm not sure how to add spaces to the small triangles to make it into a larger triangle 我想制作一个网络浏览器,但我不知道从哪里开始? - I want to make a web browser, but I'm not sure where to start? 我收到两个NullPointerExceptions,我不确定如何解决 - I'm getting two NullPointerExceptions and I'm not sure how to fix 如何确保仅使用我的origninal客户端向我的服务器发出请求? - How do I make sure only my origninal client is used to make requests to my server? 我正在为测验程序使用JTabbedPane,不确定如何获取按钮以显示答案 - I'm using JTabbedPane for my quiz program, not sure how to get my buttons to display the answers 如何制作php代码以显示我要发送到服务器的内容? - How to make php code to show what I'm sending to server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM