Change Default Java VM to Client

2019-01-26 19:06发布

问题:

I installed Oracle's Java on Fedora 17, and I noticed that when using the command java -version it returns this

java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

Java seems to run the -server option by default. The help text came up as

-server   to select the "server" VM
              The default VM is server,
              because you are running on a server-class machine.

Is there any way to change the default to client?

回答1:

The default setting is defined in the file jvm.cfg. A content like

-client KNOWN
-server KNOWN

defines the client as the default.

-server KNOWN
-client KNOWN

sets the server as the default.

Source: www.rgagnon.com/javadetails/java-0566.html

jvm.cfg location

Unknown Mac OS X version:

/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre/lib/jvm.cfg

Mac OS X version 10.9 without installing JDK:

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jvm.cfg

Mac OS X version 10.9 with installed JDK version 1.8.0_u92:

/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/jvm.cfg


You can find your jvm.cfg from the command line (Terminal.app) using the command $ locate /jvm.cfg. You might need to update your locate database first, using the command: $ sudo /usr/libexec/locate.updatedb



回答2:

From the docs:

Note: For J2SE 5.0, the definition of a server-class machine is one with at least 2 CPUs and at least 2GB of physical memory.

So there doesn't seem any way to alter the server-class machine detection technique, I'm guessing you will have to stick to passing the -client VM argument if you need it on your machine.

Also worth noting is that this page is for Java 5, so things might be different with Java 6 and higher.



回答3:

Starting with Java 5, you can specify this as an option to the JVM:

  • the -client option will make the VM start in client mode. In this mode, the start-up will be much faster.
  • the -server option will make the VM start in server mode. The start-up will be slower, but in the long run, it will execute faster.

See this question for more details about the differences about the 2 modes.

If you do not specify these options, the VM will check to see if you have at least 2 CPUs and at least 2 GB RAM. If you do, then it will start in server mode.

You can see the tables about how these decisions are made:

  • here for Java 5
  • here for Java 6 and
  • here for Java 7

FYI: they are all the same.