Thursday, March 10, 2011

How to set JVM Heap size?

How to set JVM Heap size?
Heap is basically a portion of memory that is allocated to your program. In Java heap memory is used for storing all objects. Java heap is actually the memory allocated to JVM applications.
Default Java heap size is 128 MB which is configurable. You can use the –Xms and –Xmx to define minimum and maximum heap memory that JVM can use.
To define the JVM heap size used for tomcat there are two ways:
1.       Create environment variable CATALINA_OPTS and set it to “-Xms512m -Xmx512m”. For e.g.,

export CATALINA_OPTS=”-Xms256m -Xmx512m”  (bash).

The above command defines that the minimum memory set for Tomcat JVM is 256 and Maximum is 512.

2.       Create environment variable JAVA_OPTS similar to CATALINA_OPTS. The difference between both these variables is none except that CATALINA_OPTS is used by only tomcat. Whereas JAVA_OPTS is used by tomcat as well as other web servers.. so if you simply want to configure for tomcat use CATALINA_OPTS otherwise for setting it globally use JAVA_OPTS.

No comments:

Post a Comment