≡ Menu

12 mostly used java command line options

  •  
  •  
  •  

Configuring the correct java command line options is primal for any Application Server. If you get it wrong, even slightly, the results can be devastating.

Here are the 12 mostly used java command line options. These are for Oracle Hotspot JVM version 7 and earlier.

Note: Options that begin with -X are non standard and not guaranteed to work in all flavors of VMs. And as per Oracle, options that begin with -XX are not stable. I say don’t worry too much about it. They are stable.

1. -Xms

The minimum size of the Heap. This is the memory that will be allocated when the JVM starts up.

Importance: When you set this too low, the JVM will need to expand the heap as required. Expansion can be an expensive process. When you set this too high, you might end up having more memory allocated than required. This means Garbage Collection (GC) is going to run longer as it needs to scan through larger heap.

Example: -Xms256m

2. -Xmx

The maximum size of the Heap. .

Importance: This is the ultimate ceiling on the heap and when this limit is breached, the infamous ‘OutOfMemory’ aka OOM is thrown. When this is too low, you may run into OOM error. When this is too high, the Garbage Collection (GC) is going run longer as it needs to scan through larger heap.

Example: -Xmx1024m

3. -client

Starts VM in client mode. Note that if your Java is 64bit, server VM is chosen by default even if you specify this option.

Importance: Client VM starts up quickly, but is not intended for running server applications.

4. -server

Starts VM in server mode. Note that if your Java is 64bit, server VM is chosen by default even if you specify this option.

Importance: Server VM starts up little bit slower compared to client VM, but is intended for running server applications.

5. -verbose:gc

Logs Verbose Garbage Collection info.

Importance: Can’t imagine how you cannot afford to have verbose GC enabled. It is an extremely low overhead logging and can be a life saver in case of OOM errors

6. -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

Provides Detailed GC information along with Time stamps. Extremely useful.

Importance: Super useful when dealing with OOM.

7. -Xloggc:<GC log file name>

Logs Verbose GC to the specified file.

Importance: Useful to redirect the output to a particular file of your choice.

8. -XX:MaxPermSize=size

Specifies the Maximum Permanent generation size.

Importance: Perm Gen stores the class files (not objects). If you are using lot of third party tools such as APM agents etc, give at least 256 MB for perm gen. Otherwise OOM might occur.

Example: -XX:MaxPermSize=256m

9.-XX:NewRatio=<ratio>

Ratio of old/new generation Heap

Importance: This determines the generation sizes. A ratio of 2 means, old gen will get 2/3 of the heap and new gen would get 1/3 of the heap.

10. -XX:+UseG1GC

A new Garbage collector from Oracle – Garbage First Garbage collector. Attempts to clean up areas of heap that has the least amount of live objects

11. -XX:-UseConcMarkSweepGC

Uses the Garbage Collector Concurrent Mark and Sweep.

Importance: If you need to avoid longer pause times, go with this collector as it works along side the application (instead of pausing the application totally). On the other hand, if you don’t mind occasional long GC pauses but would rather have excellent throughput, go with -XX:-UseParallelGC

12. -javaagent:<jar>

Loads a java agent.

Importance: This is how you instrument you application with a third party agent. For example, Wily Introscope or AppDynamics Application Performance Management Agent.

There you have it. 12 mostly used Java command line options. For full reference, check out the following links:

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

 


  •  
  •  
  •  
{ 0 comments… add one }

Leave a Comment