You are on page 1of 2

Memory Settings for Tomcat

Tomcat runs as a deamon under Linux or application/service on Windows. Depending on your setup and operating setup please find the instructions to set the memory for Tomcat. By default, Tomcat sets its own memory size at around 64MB which by far this is not enough for web applications. You can set the "start size", the "maximum size" and you also need to up the heap space. to find out the proper values for your platform you will need to issue the command "java -X" in the terminal. -Xms<size> set initial Java heap size -Xmx<size> set maximum Java heap size -Xss<size> set java thread stack size Once you know your parameters you should allocate about 80% of your available Ram to Tomcat.

Increase Memory
Linux
To set the memory you should have a file called "setenv.sh" in your /tomcat/bin directory. If the file does not exsist you should create it. Within the file set the parameters like;
export JAVA_OPTS="-Xms256m -Xmx512m"

Then restart Tomcat to apply the new settings.

Windows (started manually)


To set the memory you should have a file called "setenv.bat" in your /tomcat/bin directory. If the file does not exsist you should create it. Within the file set the parameters like;
set JAVA_OPTS="-Xms256m -Xmx512m"

Then restart Tomcat to apply the new settings.

Windows (as a service)


If you are running Tomcat on a Windows server, then Tomcat should be installed as a service. To set the maximum memory limit of the service, click Start, then *Run..." and type regedt32. In the registry editor, click to HKEY_LOCAL_MACHINE > SOFTWARE -> Apache Software Foundation -> Procrun 2.0 -> Tomcat> Parameters -> Java. Here you will see an entry for

JvmMx, which is the "maximum memory" setting. Double-click JvmMx to edit, change the Base to "Decimal" and adjust the value as necessary.

Permanent Memory Generation


In some cases the server can run out of a different type of memory (Permanent Generation), and if this is the case the above settings may not help solve the memory issue. A problem like this may occur when running multiple applications on the same server. If you are experiencing this type of error, you would most likely see the following error in your logs:
java.lang.OutOfMemoryError: PermGen space

To increase the level of this memory another java parameter will need to be added:
-XX:MaxPermSize=128m

Linux
As explained above all these settings take place in the setenv.sh. Add the following now;
export JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=128m"

Windows (started manually)


As explained above all these settings take place in the setenv.bat. Add the following now;
set JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=128m"

Windows (started as a service)


As mentioned above, for Windows services this is done by editing the service "Options" parameter in the registry.