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

3

6

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.

Snowonthemountain answered 17/7, 2012 at 11:37 Comment(2)
Possible duplicate: #1833629Monkeypot
It is listed in VisualVm. I think you have to look better. If you can't find it, it was probably not set.Wale
A
4

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

Affine answered 17/4, 2013 at 22:29 Comment(0)
S
3

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
Squamation answered 17/7, 2012 at 12:2 Comment(0)
G
2

Open JConsole -> Check for java.lang.Runtime -> VmName attribute. It displays Java HotSpot(TM) Client VM for me. If you were running a server mode - check the value it displays for you.

If you need to check this using a program - you would need to query the management factory for the above attribute.

Gutta answered 17/7, 2012 at 11:59 Comment(1)
On my regular windows workstation the default is 'java.vm.name=Java HotSpot(TM) Client VM' and I can't set the server option as the server jvm is not installed. On the Windows 2008 Server the default is ‘Java HotSpot(TM) 64-Bit Server VM’, this is as I’d expect. However when I force the jvm to ‘-client’ the runtime java.vm.name is still ‘Java HotSpot(TM) 64-Bit Server VM’. Why is this? The server install simply doesn’t have the client JVM installed?Snowonthemountain

© 2022 - 2024 — McMap. All rights reserved.