Monday, April 25, 2011

Playing with JVM heam size

Java programs executes in JVM uses Heap of memory to manage the data. If your Java program requires a large amount of memory, it is possible that the virtual machine will begin to throw OutOfMemoryError instances when attempting to instantiate an object. The default heap size if 1 MB and can increase as much as 16 MB.

Java heap space setting from command line:
  1. -Xms for initial heap size
  2. -Xmx for maximum heap size 
  3. -Xss<size>   for set java stack size
     


Initial heap size 128m, max heap size 256m:
java -Xms128m -Xmx256m MyApp


Initial heap size 256m, max heap size 256m:
java -Xms128m -Xmx256m MyApp


Max heap size can't be less than initial heap size:
java -ms256m -mx128m MyAppError occurred during initialization of VM
Incompatible initial and maximum heap sizes specified

No comments:

Post a Comment

Chitika