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(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
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 catalina.sh or catalina.bat file.
How to fix it?
1) Find where is Cataline.sh located. We need to make some changes in “catalina.sh” file.
P.S Cataline.sh is located at \tomcat folder\bin\catalina.sh
2) Assign following line to JAVA_OPTS variable and add it into catalina.sh 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 catalina.sh 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: catalina.sh 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. cygwin=false os400=false darwin=false case "`uname`" in CYGWIN*) cygwin=true;; OS400*) os400=true;; Darwin*) darwin=true;; esac # resolve links - $0 may be a softlink PRG="$0"
3) Done. Restart Tomcat.
- Java Core Technology - Java RegEx, Java XML, Java I/O, Java Misc
- J2EE Frameworks - Hibernate, Spring 2.5, Spring MVC, Struts 1.x, Struts 2.x
- Build Tools - Maven, Archiva
- Unit Test - jUnit, TestNG
- Client Scripts - jQuery
Please help I added the above line i get this error while calling ./ahutdown.sh
Exception in thread “main” java.lang.NoClassDefFoundError: $/-Djava/awt/headless=true
Please reply thanks
Thank you.
uhmmmm, that’s great, but how can i do this in windows tomcat.
There is no catalina.sh file, just tomcat5.exe, dll, and jar files.
There is a Configure.. option in tomcat monitor, but I’m not sure how to configure this options.
Not familiar with the Window version, cant find the Java options in the “conf” folder as well.
But you can run the “tomcat6w.exe”, click on the “Java” tab, and configure the value in the Java Options field.
Excellent! Works well now!
[...] http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ [...]
thank you… uffffffff.. many hours searching the solution
Thanks, very cool!
Thank You sir
you should not edit your catalina.sh file to shove these things in there – you should instead create a
“setenv.sh” file that catalina calls when it runs and put the export JAVA_OPTS=” ” line in that setenv.sh file.
you have your point, thanks for sharing
Thank you so much!
Thanks a lot!
Thank you :0
[...] not even the deployment of Sonar worked. Thus, you have to change your “catalina.sh” according to this article. Search for the JAVA_OPTS variable and add these [...]
Thanks buddy!!!
Thank buddy