How to avoid Classloader Leak with JPA, Hibernate and Spring on Tomcat

后端 未结 2 510
广开言路
广开言路 2021-01-03 09:13

The Open J2EE Web Template is a showcase application for wicket - JPA with Spring and Hibernate that runs on a Tomcat7 servlet container. Its Maven build script appears to u

相关标签:
2条回答
  • 2021-01-03 10:01

    Configure a logging framework other than java.util.logging e.g. Logback.

    If no logging is configured at all, or if java.util.logging is configured, jboss logging will create a classloader leak via the JDK bug Level.known can leak memory. See the stack trace in the question where jboss logging creates the custom java.util.logging.Level.

    0 讨论(0)
  • 2021-01-03 10:07

    I have seen this same webapp memory leak on Tomcat7 + OpenJPA2.4.1 + ValidationAPI1.x + hibernate-validator-5.2.1 + jboss-logging.jar

    Problem is indeed jboss-logging.jar creates a subclass of java.util.logging.Level instances. May not be a problem if jar is provided by J2EE container but will happen with mywebapp/WEB-INF/lib distribution. I have created a fork of package to disable subclassing. Problems went away and webapp hot redeployments work fine.

    Heapdump of GC root path indicates a source of problem, JDKLevel subclass keeps a webapp in memory and soon JVM run out of PermGen memory.

    this     - value: org.apache.catalina.loader.WebappClassLoader #2
     <- <classLoader>     - class: org.jboss.logging.JDKLevel, value: org.apache.catalina.loader.WebappClassLoader #2
      <- <class>     - class: org.jboss.logging.JDKLevel, value: org.jboss.logging.JDKLevel class JDKLevel
       <- levelObject     - class: java.util.logging.Level$KnownLevel, value: org.jboss.logging.JDKLevel #6
        <- [1]     - class: java.lang.Object[], value: java.util.logging.Level$KnownLevel #12
         <- elementData     - class: java.util.ArrayList, value: java.lang.Object[] #5160 (10 items)
          <- value     - class: java.util.HashMap$Entry, value: java.util.ArrayList #3532
           <- [0]     - class: java.util.HashMap$Entry[], value: java.util.HashMap$Entry #21639
            <- table     - class: java.util.HashMap, value: java.util.HashMap$Entry[] #280 (16 items)
             <- intToLevels (sticky class)     - class: java.util.logging.Level$KnownLevel, value: java.util.HashMap #375
    

    edit Created JBoss Jira ticket for this bug (https://issues.jboss.org/browse/JBLOGGING-118)

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题