Coder Perfect

Tomcat 7: How to set initial heap size correctly?

Problem

By adding the following line to catalina.sh, I was able to adjust the initial heap size of a Tomcat 7 (CentOS, java -version: 1.6.0 25-b06) instance:

export CATALINA_OPTS="-Xms=512M -Xmx=1024M"

Tomcat fails to start, and the following message is logged to catalina.out:

Invalid initial heap size: -Xms=512m
Could not create the Java virtual machine.

What’s the problem with these choices?

Asked by GLA

Solution #1

You must not use the symbol =. Simply use the following:

export CATALINA_OPTS="-Xms512M -Xmx1024M"

Answered by Joachim Sauer

Solution #2

To correctly increase the java heap size for Tomcat7 (linux distributions), run the following command:

echo 'export CATALINA_OPTS="-Xms512M -Xmx1024M"' > /usr/share/tomcat7/bin/setenv.sh

Answered by MeJ

Solution #3

You may not require export; simply add the following line to catalina.sh:

CATALINA_OPTS="-Xms512M -Xmx1024M"

Answered by Phat H. VU

Solution #4

setenv.sh is preferable since it allows you to simply transfer settings from one machine to another or from one Tomcat version to another. From one Tomcat version to the next, catalina.sh changes. With any version of Tomcat, though, you may keep your setenv.sh unmodified.

Another advantage is that adding it to your backup or versioning system makes it easy to follow the history of your modifications. Only your own changes will be visible if you look at how setenv.sh has changed over time. If you use catalina.sh, you’ll constantly see not only your changes, but also the changes that arrived with each later Tomcat version.

Answered by mentallurg

Solution #5

Navigate to the “Tomcat Directory”/bin folder.

Create setenv.sh if you’re using Linux, otherwise If you’re using Windows, make a setenv.bat file.

setenv.* file content:

export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx8192m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"

Restart Tomcat with the modified parameters.

The complete explanation and facts may be found here.

http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/

Answered by Musa

Post is based on https://stackoverflow.com/questions/6897476/tomcat-7-how-to-set-initial-heap-size-correctly