Schlagwort-Archive: JVM

Useful JVM arguments and properties

In this article I try to list some of the most valuable JVM command line arguments and properties.I will not focus on arguments and properties you use in your everyday work with your IDE like -Xmx and -Xms. The focus is on rarely use arguments and properties where you know they exist but have to search them erverytime you want to use them.

I start with application properties:

-Dcom.sun.management.jmxremote

With Java5 a profiler is shipped with every JDK. The profiler is called JConsole and can be found in the bin directory of the JDK. In order to connect JConsole with your running application the property -Dcom.sun.management.jmxremote has to be set during startup. More information about how to use JConsole can be found in an article from Ted Neward at IBM developerWorks.

-XX:+HeapDumpOnOutOfMemoryError

If your application crashes with an OutOfMemoryError and you cannot find the problem then this switch may help you. In case of an OutOfMemorryError the JVM creates a heap dump in the working directory of your application. This heap dump can be analysed with JConsole to detected the memory consuming object(s). If you need to store the heap dump in a different location you can set the location with -XX:HeapDumpPath=<path>.

-XX:MaxPermSize=<size>

I use this argument to increase the size of the permanent generation space of the memory. This need to be done for example if a lot of class definitions are loaded into memory. The first time I needed to increase size of the permanent generation I wanted to find all classes in the classpath which implement a specific interface. This was done in a test framework. I never needed this argument in production mode.

-verbose:class

This argument should not be used in production mode of your application. If you turn on this option the JVM will display all loaded classes to the console.

-verbose:gc

As the argument before this option should also not be used in production mode. The JVM will print every action of the garbage collector to the console. With this option you can easily find out if your application has a memory leak.

 

Hopefully you have found some useful command line arguments to use in your project. If you know additional arguments you came across, please write a comment and I will add them to this list.