简体   繁体   中英

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.

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.

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

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)

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?

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

You can do

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

Which on my machine returns either:

Java HotSpot(TM) Client VM

or

Java HotSpot(TM) 64-Bit Server 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.

I had a very similar question which I asked on ServerFault . I would say, if you care which version is run, always use -client or -server.

Well, if you explicitly start with the -server command line prompt, you are running in server mode. 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.

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.

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

> 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM