Tomcat 7: How to set initial heap size correctly?

JavaLinuxTomcat7Heap Memory

Java Problem Overview

I was trying to adjust initial heap size of a tomcat 7 (CentOS, java -version: 1.6.0_25-b06) instance by adding the following line to

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

Starting up tomcat fails and logs the following message to catalina.out:

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

What is wrong with these options?

Java Solutions

Solution 1 - Java

You must not use =. Simply use this:

export CATALINA_OPTS="-Xms512M -Xmx1024M"

Solution 2 - Java

Use following command to increase java heap size for tomcat7 (linux distributions) correctly:

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

Solution 3 - Java

You might no need to having export, just add this line in :

CATALINA_OPTS="-Xms512M -Xmx1024M"

Solution 4 - Java is better, because you can easily port such configuration from one machine to another, or from one Tomcat version to another. changes from one version of Tomcat to another. But you can keep your unchanged with any version of Tomcat.

Another advantage is, that it is easier to track the history of your changes if you add it to your backup or versioning system. If you look how you changes along the history, you will see only your own changes. Whereas if you use, you will always see not only your changes, but also changes that came with each newer version of the Tomcat.

Solution 5 - Java

Go to "Tomcat Directory"/bin directory

if Linux then create else if Windows then create setenv.bat

content of setenv.* file :

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

after this restart tomcat with new params.

explanation and full information is here

Solution 6 - Java

Take care with change in Debian distributions! I tried to change CATALINA_OPTS in my Debian 7 and the results where that tomcat didn't start anymore. Thus I solved this issue by changing the property JAVA_OPTS in place of CATALINA_OPTS, like this

export JAVA_OPTS="-Xms512M -Xmx1024M"

Solution 7 - Java

Just came across this and I've implemented Nathan's solution:

add the line (changing the values as required):

export JAVA_OPTS="-Xms512M -Xmx1024M"

to /usr/share/tomcat7/bin/

If that file doesn't exists then create it and

chown root:root it
chmod 755 it

And then restart tomcat and check it with

ps aux | grep logging

Which should just pick up the instance and show the java parms

Solution 8 - Java

It works even without using 'export' keyword. This is what i have in my (/usr/share/tomcat7/bin/ and it works.

OS : 14.04.1-Ubuntu Server version: Apache Tomcat/7.0.52 (Ubuntu) Server built: Jun 30 2016 01:59:37 Server number:

JAVA_OPTS="`umask` -server -Xms6G -Xmx6G -Xmn1400m -XX:HeapDumpPath=/Some/logs/ -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:+UseCompressedOops"

Solution 9 - Java

After spending good time time on this . I found this is the what the setenv.bat must look like . No " characters are accepted in batch file.

set CATALINA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=768m

echo hello "%CATALINA_OPTS%"

Solution 10 - Java

If it's not work in your centos 7 machine "export CATALINA_OPTS="-Xms512M -Xmx1024M"" then you can change heap memory from vi /etc/systemd/system/tomcat.service file then this value shown in your tomcat by help of ps -ef|grep tomcat.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGLAView Question on Stackoverflow
Solution 1 - JavaJoachim SauerView Answer on Stackoverflow
Solution 2 - JavaMeJView Answer on Stackoverflow
Solution 3 - JavaPhat H. VUView Answer on Stackoverflow
Solution 4 - JavamentallurgView Answer on Stackoverflow
Solution 5 - JavaMusaView Answer on Stackoverflow
Solution 6 - JavaRoberto C. Rodriguez-HidalgoView Answer on Stackoverflow
Solution 7 - JavaAPAView Answer on Stackoverflow
Solution 8 - JavamdevView Answer on Stackoverflow
Solution 9 - JavaDinesh RajendranView Answer on Stackoverflow
Solution 10 - JavaBirendra RawatView Answer on Stackoverflow