what to do with tomcat PermGen space

SKing7 picture SKing7 · Apr 10, 2012 · Viewed 82.9k times · Source

BACKGROUND: I have a web Project which uses JSP. The IDE is Eclipse. The configuration of tomcat is: Automatically publish when resources change and publishing interval is "1 second".

A property file in the classes folder which used to save some settings.It also can be dynamically modified by the servlet. The modify operation is trigerred by the save button in the JSP.

PROBLEM: After several save operation, Tomcat come with java.lang.OutOfMemoryError: PermGen space.

LOG MESSAGE

java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1815)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1064)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4238)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3083)
    at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:404)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1279)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1571)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1560)
    at java.lang.Thread.run(Thread.java:662)

Answer

Scott Linford picture Scott Linford · Apr 20, 2012

Tomcat does need a lot of permgen. 512m is not an unreasonable max. However it only delays the hot-deploy leak. Permgen will grow ~25mb per hotdeploy, which, in Eclipse, might be every time you save a Java file. 512m disappears fast if you have a Ctrl+S twitch like me.

The solution: allow Java to kick class definitions out of memory, i.e., garbage collect byte code. Add these along with your boosted permgen size:

-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC