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)
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
SKing7
  • 301
  • 2
  • 4
  • 4
  • Potential duplicate. http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error – Phani Apr 10 '12 at 07:54
  • 3
    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. – Jon Apr 10 '12 at 08:57
  • 2
    Please go through the below article which completely explains configuring tomcat to increase permGen [Tomcat PermGen Space](http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/) – Phani Apr 10 '12 at 07:52
  • Possible duplicate of [PermGen space Error in tomcat](http://stackoverflow.com/questions/10392255/permgen-space-error-in-tomcat) – Steve Chambers Nov 04 '15 at 14:38

7 Answers7

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
dldnh
  • 8,923
  • 3
  • 40
  • 52
Scott Linford
  • 441
  • 3
  • 3
15

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

stt
  • 342
  • 2
  • 7
  • 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 be – SKing7 Apr 10 '12 at 09:25
  • 2
    It's -Xms256m -Xmx1024m actually. Xms is the start size, and Xmx is max heap size. – Marcio Aguiar Apr 06 '13 at 13:54
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

5

setting like this:

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

enter image description here

Vy Do
  • 46,709
  • 59
  • 215
  • 313
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
BabaNew
  • 884
  • 1
  • 13
  • 27
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

Community
  • 1
  • 1
Nicks
  • 16,030
  • 8
  • 58
  • 65
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.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
Purushothaman
  • 417
  • 4
  • 6