问题
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)
回答1:
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
回答2:
You may set environment variable named : "JAVA_OPTS
" and set value of it as follows -Xms256m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m
回答3:
FOR ECLIPSE
- Go to server properties
- Go to platform
- Now in VM argument write this -Xms256m -Xmx256m -XX:PermSize=256m -XX:MaxPermSize=512m
FOR NETBEANS
- Go to Netbeans folder/etc/
- open netbeans.config in any editor
- 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
回答4:
setting like this:
-Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m
回答5:
Just configure it from the apache tomcat interface:
- start C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\Tomcat8w.exe (or you may just search in windows start for "Configure Tomcat");
- Go to Java tab;
- Set the required space in the input fields:
回答6:
Just to add for Windows, if someone is still stuck:--
- Open catalina.bat file (located at Apache tomcat installation folder/bin)
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
Restart Tomcat and its done.
You can find nice explanation here
回答7:
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.
来源:https://stackoverflow.com/questions/10085028/what-to-do-with-tomcat-permgen-space