Tomcat – java.lang.OutOfMemoryError: PermGen space

Tomcat production server sometime will hit the following java.lang.OutOfMemoryError: PermGen space error.

java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(

It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, you should increase the memory by make change in or catalina.bat file.

How to fix it?

1) Find where is located. We need to make some changes in “” file.
P.S is located at \tomcat folder\bin\

2) Assign following line to JAVA_OPTS variable and add it into file.

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

Partial example of the file

# JSSE_HOME (Optional) May point at your Java Secure Sockets Extension
# (JSSE) installation, whose JAR files will be added to the
# system class path used to start Tomcat.
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process, when start (fork) is used
# $Id: 609438 2008-01-06 22:14:28Z markt $
# -----------------------------------------------------------------------------

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

# OS specific support. $var _must_ be set to either true or false.
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;

# resolve links - $0 may be a softlink

3) Done. Restart Tomcat.
You should change the “Xms” and “PermSize” value base on your server capability.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s