Activities

July 2011
M T W T F S S
« Jun   Aug »
 123
45678910
11121314151617
18192021222324
25262728293031

Tomcat : How to increase the Java heap size

Most of the Java applications can be more resource intensive and require more dedicated RAM for processing thread or stack type requests.

There is two method to set this variable.
1. Setting JAVA_OPTS variables in system wide.
So all other java application would be utilize the this heap size reservation and it will not be usefull if you are running mulltiple java application on the same server as it is using the shared heap-size.
Set environmental variable as follows

#export JAVA_OPTS="-Xms512m -Xmx1024m"

2. Setting JAVA_OPTS variables in Tomcat config. (Recommended)
Tomcat is using few environment variables to identify certain values like JAVA_HOME, CATALINA_BASE, CATALINA_TMPDIR and CATALINA_OPTS etc. These values will be find from the catalina.sh (Linux) in the tomcat installation binary folder which execute every time when tomcat starts.

How to set the values
Either you need to add the following value in catalina.sh or set the variable “CATALINA_OPTS” in system wide.

# export CATALINA_OPTS="-Xms512m -Xmx1024m"

Xms : Minimum Heap size memory
Xmx : Maximum heap size memory ( This would not be greater than system physical memory)

For verifying
[root@demo ec2-user]# echo $CATALINA_OPTS
-Xms512m -Xmx1024m
[root@demo ec2-user]#

You may create a file inside “/etc/profile.d” folder and create a sh file to set variables (/etc/profile.d/java.sh”).

Sometimes you may need to increase permsize to get benefit of heap size increment.

How do I increase the Persize

Add this line in top of catalina.sh
export JAVA_OPTS=”-XX:PermSize=64M -XX:MaxPermSize=128M”

[root@demo ec2-user]# echo $JAVA_OPTS
-XX:PermSize=64M -XX:MaxPermSize=128M
[root@demo ec2-user]#

My java.sh file entries are,

#vi /etc/profile.d/java.sh
JAVA_HOME=/opt/jdk1.6.0_21
JAVA_FONTS=/usr/share/fonts/truetype
ANT_HOME=/usr/share/ant
JAVACC_HOME=/usr/java/javacc
SPRING_HOME=/usr/local/spring-framework-1.1.4
CLASSPATH=.:$JAVA_HOME/lib
CATALINA_BASE=/opt/apache-tomcat-7.0.2
CATALINA_HOME=/opt/apache-tomcat-7.0.2
CATALINA_TMPDIR=/opt/apache-tomcat-7.0.2/temp
JBOSS_HOME=/usr/local/jboss-4.0.3SP1
PATH=$JAVA_HOME:$JAVA_HOME/bin:$JAVACC_HOME/bin:$ANT_HOME/bin:$CATALINA_HOME/bin:$JBOSS_HOME/bin:ANT_HOME/bin:$PATH
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/glib-2.0.pc
export PKG_CONFIG_PATH
LD_LIBRARY_PATH=/usr/local/lib;export LD_LIBRARY_PATH;
export PATH JAVA_HOME JAVA_FONTS ANT_HOME JAVACC_HOME CATALINA_BASE CATALINA_HOME CATALINA_TMPDIR JBOSS_HOME
export CLASSPATH
export CATALINA_OPTS="-Xms512m -Xmx1024m"

export JAVA_OPTS=”-XX:PermSize=64M -XX:MaxPermSize=128M”

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>