[java] Tomcat 7: How to set initial heap size correctly?

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 catalina.sh:

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?

This question is related to java linux tomcat7 heap-memory

The answer is


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

CATALINA_OPTS="-Xms512M -Xmx1024M"

setenv.sh is better, because you can easily port such configuration from one machine to another, or from one Tomcat version to another. catalina.sh changes from one version of Tomcat to another. But you can keep your setenv.sh 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 setenv.sh changes along the history, you will see only your own changes. Whereas if you use catalina.sh, you will always see not only your changes, but also changes that came with each newer version of the Tomcat.


Go to "Tomcat Directory"/bin directory

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

content of setenv.* file :

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

after this restart tomcat with new params.

explanation and full information is here

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


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/setenv.sh

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


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

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

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"

It works even without using 'export' keyword. This is what i have in my setenv.sh (/usr/share/tomcat7/bin/setenv.sh) 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: 7.0.52.0

JAVA_OPTS="-Dorg.apache.catalina.security.SecurityListener.UMASK=`umask` -server -Xms6G -Xmx6G -Xmn1400m -XX:HeapDumpPath=/Some/logs/ -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:+UseCompressedOops -Dcom.sun.management.jmxremote.port=8181 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="$JAVA_OPTS -Dserver.name=$HOSTNAME"

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.


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%"


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to tomcat7

Could not load the Tomcat server configuration INFO: No Spring WebApplicationInitializer types detected on classpath Name [jdbc/mydb] is not bound in this Context I cannot access tomcat admin console? Tomcat 7.0.43 "INFO: Error parsing HTTP request header" jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class Tomcat Server not starting with in 45 seconds HTTP Status 500 - Servlet.init() for servlet Dispatcher threw exception How to fix JSP compiler warning: one JAR was scanned for TLDs yet contained no TLDs? java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Examples related to heap-memory

Node.js heap out of memory Set default heap size in Windows how to increase java heap memory permanently? What is the largest possible heap size with a 64-bit JVM? Tomcat 7: How to set initial heap size correctly? Heap space out of memory C: How to free nodes in the linked list? java.lang.OutOfMemoryError: GC overhead limit exceeded How is the default max Java heap size determined? How to increase Java heap space for a tomcat app