2

I am working with Spring sts. I am hoping my webapplication on Tomcat v7.0 Server that I added using the internal server wizard.

The server keeps running out of memory and throws Permgen error when editing java files since the server is constantly redeploying automatically (maybe? thats my understanding). Is there a way to increase the allocated permgen space for this server considering that I did not install my own copy of tomcat?

Any help or clarification would be awesome.

I added the stacktrace if this helps:


    SEVERE: Unexpected death of background thread ContainerBackgroundProcessor[StandardEngine[Catalina]]
    java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
        at org.apache.log4j.spi.LoggingEvent.(LoggingEvent.java:159)
        at org.apache.log4j.Category.forcedLog(Category.java:391)
        at org.apache.log4j.Category.log(Category.java:856)
        at org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:602)
        at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:336)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardContext.reload(StandardContext.java:4007)
        at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:425)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1546)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1524)
        at java.lang.Thread.run(Thread.java:745)

    Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
        at org.apache.log4j.spi.LoggingEvent.(LoggingEvent.java:159)
        at org.apache.log4j.Category.forcedLog(Category.java:391)
        at org.apache.log4j.Category.log(Category.java:856)
        at org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:602)
        at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:336)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardContext.reload(StandardContext.java:4007)
        at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:425)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1546)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1524)
        at java.lang.Thread.run(Thread.java:745)

Thank you :)

1000Suns
  • 251
  • 1
  • 3
  • 16
  • I am chasing a similar problem - see http://stackoverflow.com/questions/31211868/outofmemoryerror-when-hot-deploying-springmvc-app-to-tomcat7-possible-relation - and would like to ask you if the configuration of log4j or log4j2 had anything to do the leak that you found. – Steve Cohen Jul 06 '15 at 02:01
  • I never solved this. But according to my logs, it may be the JDBC driver used that is causing problems. I dont think log4j config is the cause. – 1000Suns Jul 06 '15 at 20:47

2 Answers2

2

Indeed you can increase the permgen space, which will at least postpone the OutOfmemoryError: Permgen space. It will be as simple as adding (or increasing if present) a parameter similar to the following example allocating 512m for permgen space:

java -XX:MaxPermSize=512m your.package.YourClass

Based on your description though I do believe that your application contains a classloader leak, which is happening during a redeploy. If my belief is correct, then increasing permgen space just postpones the inevitable instead of solving the underlying problem. To solve the problem, you can either do a heap dump and analyze the content or use specialized tools, such as Plumbr memory leak detector.

Full disclosure, I am affiliated with Plumbr.

Ivo
  • 444
  • 3
  • 7
0

I think you can configure the redeploy behavior and avoid the constant redeployment in the server editor. In addition to that you should also be able to set a permgen vm option in the launch configuration for the server (Run -> Run Configurations...).

Martin Lippert
  • 5,988
  • 1
  • 15
  • 18