what to do with tomcat PermGen space

2019-01-16 11:33发布

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)

7条回答
2楼-- · 2019-01-16 11:55

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
查看更多
神经病院院长
3楼-- · 2019-01-16 12:02

You may set environment variable named : "JAVA_OPTS" and set value of it as follows -Xms256m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m

查看更多
混吃等死
4楼-- · 2019-01-16 12:09

Just to add for Windows, if someone is still stuck:--

  1. Open catalina.bat file (located at Apache tomcat installation folder/bin)
  2. Set JAVA_OPTS as follows in the very start(before actually its first use anywhere in the file):--

    set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m

  3. Restart Tomcat and its done.

You can find nice explanation here

查看更多
smile是对你的礼貌
5楼-- · 2019-01-16 12:12

FOR ECLIPSE

  1. Go to server properties
  2. Go to platform
  3. Now in VM argument write this -Xms256m -Xmx256m -XX:PermSize=256m -XX:MaxPermSize=512m

FOR NETBEANS

  1. Go to Netbeans folder/etc/
  2. open netbeans.config in any editor
  3. edit this line as

netbeans_default_options="-J-client -J-Xss256m -J-Xms256m -J-XX:PermSize=256m -XX:MaxPermSize=512m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"

Thats all

查看更多
Viruses.
6楼-- · 2019-01-16 12:14

setting like this:

-Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m

enter image description here

查看更多
Evening l夕情丶
7楼-- · 2019-01-16 12:17

Tomcat server runs different JAVA and the eclipse runs in different JAVA.

So adding -XX:MaxPermSize=512m to eclipse.ini will help resolving this issue. Follow the below steps to add this to tomcat server:

  • Double click server in eclipse

  • open launch configuration

  • add "-XX:MaxPermSize=512m" to VM arguments in the Arguments tab.

查看更多
登录 后发表回答