Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if -server option set on your JVM instance

I'm trying to determine if the JVM (using jdk 1.7u3) -server option is enabled by default on my JVM instances. Based on my environment (Windows 2008 Server R2) and the Server-Class Machine detection information I'd expected it to be set though I'd like to know explicitly. Of course I could explicitly launch the JVM with the option, and I most probably will though is there a simply way to determine same.

I have already tried the following approaches, though neither seems to explicitly state what I'm looking for. Perhaps its encoded in some other details.

  1. View JVM via jVisualVM and look at JVM Arguments, not listed explicitly
  2. Programatically attempted to view the JVM arguments, matches those observed via jVisualVM

    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = RuntimemxBean.getInputArguments();     
    
  3. Use JVM option -XX:+PrintCommandLineFlags, this provided verbose details though still no evidence that the -server option was set.

like image 793
Simon Avatar asked Jul 17 '12 11:07

Simon


2 Answers

You can find that by running java -version command:

below is example for JVM running with -server flag

java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

In case of -client, it would show 64-Bit Client VM

Most of the cases it depends on number of CPU's and physical memory. More @ http://docs.oracle.com/javase/7/docs/technotes/guides/vm/server-class.html

like image 146
giddi Avatar answered Sep 18 '22 10:09

giddi


You can use System.getProperty("java.vm.name") and parse the string.

Example:

public class Test {
  public static void main(String{[] args) {
    System.out.println(System.getProperty("java.vm.name"));
  }
}

This example will result in:

OpenJDK Client VM

or if you are using -server:

OpenJDK Server VM
like image 25
marty bourque Avatar answered Sep 22 '22 10:09

marty bourque