How much memory do we have to set for JAVA_OPTS in catalina.sh

Dilip Rajkumar picture Dilip Rajkumar · Mar 7, 2012 · Viewed 12.7k times · Source

Following are my system configuration

java version "1.6.0_17"  
Tomcat 6.0.18  
OS : Cent OS 5.7

enter image description here

Following is my JAVA_OPTS in Catalina.sh

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=1024m -XX:PermSize=256m -XX:MaxPermSize=1024m -XX:+DisableExplicitGC"

I am getting the following error on heavy usage. And the Tomcat Crashes..

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Unknown Source)
    at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
    at java.lang.AbstractStringBuilder.append(Unknown Source)
    at java.lang.StringBuffer.append(Unknown Source)
    at org.htmlparser.parserHelper.TagParser.checkFinishedState(TagParser.java:157)
    at org.htmlparser.parserHelper.TagParser.automataInput(TagParser.java:93)
    at org.htmlparser.parserHelper.TagParser.find(TagParser.java:76)
    at org.htmlparser.tags.Tag.find(Tag.java:192)

Can any one please say the correct configuration for JAVA_OPTS so that I will not get this error. Please help me Thanks in advance.

EDIT : Finally I gave the java opts as like this

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx3072m -XX:NewSize=256m -XX:MaxNewSize=1024m -XX:PermSize=256m -XX:MaxPermSize=1024m"

Answer

Sebastian Łaskawiec picture Sebastian Łaskawiec · Mar 7, 2012

JVM memory tuning is not an easy task.

Increasing JVM memory is the first thing you should do, but also take a look at some tools for investigating JVM memory consumption. You might start with jvisualvm or jconsole (both should be placed in ${JDK_HOME}/bin).