what to do with tomcat PermGen space
Asked Answered
L

7

27

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)
Laurustinus answered 10/4, 2012 at 7:48 Comment(4)
Please go through the below article which completely explains configuring tomcat to increase permGen Tomcat PermGen SpaceFeatherbrain
Potential duplicate. #88735Featherbrain
I get this error with Tomcat whenever people redeploy a web application repeatedly, without restarting Tomcat. Because of a leak associated with the classloading process, the permgen space gets a little bit more full with each redeploy. Increasing the permgen size will delay the point at which it runs out of memory, but really, you need to ensure Tomcat gets bounced when you redeploy a webapp.Weight
Possible duplicate of PermGen space Error in tomcatZales
R
34

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
Rennie answered 20/4, 2012 at 15:18 Comment(2)
@dldnh can you please mention the full line that should be added to the setenv.sh fileDona
Any reason why this isn't enabled by default?Corinnecorinth
L
15

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

Laureenlaurel answered 10/4, 2012 at 8:52 Comment(2)
It seems to avoid the problem,but not a good solution. I doubt that saving datas frequently in the property file is a wrong design, if it's bad,what should it beLaurustinus
It's -Xms256m -Xmx1024m actually. Xms is the start size, and Xmx is max heap size.Ornithorhynchus
D
6

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

Detachment answered 17/6, 2016 at 5:25 Comment(0)
B
5

setting like this:

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

enter image description here

Banbury answered 16/7, 2015 at 2:48 Comment(0)
B
3

Just configure it from the apache tomcat interface:

  1. start C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\Tomcat8w.exe (or you may just search in windows start for "Configure Tomcat");
  2. Go to Java tab;
  3. Set the required space in the input fields: enter image description here
Bodnar answered 30/8, 2018 at 12:10 Comment(0)
Z
1

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

Zuniga answered 2/12, 2016 at 0:40 Comment(0)
M
0

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.

Meloniemelony answered 7/4, 2016 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.