Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure I'm using the "server" JVM?

Tags:

java

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.

like image 582
itsadok Avatar asked Dec 02 '09 14:12

itsadok


2 Answers

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.

like image 140
Jared Russell Avatar answered Oct 15 '22 00:10

Jared Russell


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.

like image 29
Jason S Avatar answered Oct 15 '22 00:10

Jason S