How to Tune a Java Virtual Machine (JVM)

The Java Virtual Machine (JVM) runs your Java programs. Sometimes the default configuration that the JVM comes with may not be the most efficient for your program.

In such a case, you need to tune the JVM to improve its performance. You can adjust the default parameters until you achieve the desired performance for your application.

There are three types of command line options that you can use when tuning your JVM.

Standard options

Standard options come with every JVM compiler. You can use them to perform actions like setting classpath or checking your JRE version. These options begin with a dash ( - ) prefix and end with the option name.

For example, to check your JRE version, enter the following command line:

java -version

Non-standard options

The non-standard options are specific to your JVM implementation. The most common implementation is the Hotspot JVM, which you probably already have installed on your computer.

Non-standard options start with -X. Unlike standard options, you can do a lot more with non-standard options.

These options allow you to set parameters to increase heap memory, nursery size or garbage collector type. This is where most of the performance tuning takes place.

For example, to set the minimum heap memory for your application to 1GB and the maximum to 3GB, use the command below:

java -Xms1g -Xmx3g JavaClass

Advanced options

You can use advanced options to control actions at the system level. In general, you should not use these options unless you have a deep understanding of your system.

It is also important to note that these options are subject to change at any time without notice. You can track the changes made to the HotSpot JVM through the Oracle documentation.

Advanced options start with -XX. Like non-standard options, they are not guaranteed to be available in all JVM implementations. The syntax of these options is similar to that of the non-standard options.

For example, to set the maximum metaspace size to 85004KB, use the following command:

java -XX:MaxMetaspaceSize=85004k JavaClass

Many options to tweak the JVM

You can tune your JVM with several types of options. But there are many options available to control various low-level settings.

You can check the available options by running java -X or you can check the Oracle documentation for more details.

Update 08 July 2022
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile