Tomcat/Grails memory leaks

2019-04-29 03:25发布

I'm seeing the following in my catalina.out log everytime I undeploy by grails application:

INFO: Closing Spring root WebApplicationContext
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/appName] appears to have started a thread named [PoolCleaner[935209663:1403137427048]] but has failed to stop it. This is very likely to create a memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1@7b50a485]) and a value of type [java.util.HashMap] (value [{}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2@6b615702]) and a value of type [java.util.HashMap] (value [{DEFAULT=0}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1@7b50a485]) and a value of type [java.util.HashMap] (value [{}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2@6b615702]) and a value of type [java.util.HashMap] (value [{DEFAULT=0}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

I actually see over a 100 of the hibernate ones. It seems like there was a memory leak related to domain classes that was fixed in Grails 2.0, but I'm using 2.35. If this is most likely something in my app that is causing these leaks I'd like to know the how to trouble shoot them. Thanks...

1条回答
唯我独甜
2楼-- · 2019-04-29 04:27

Is there any HashMap type field is defined in your domain . And you are populating that domain in your bootstrap.groovy ?

There is some suggestion using HashMap

1. Work with smaller batches of HashMap objects to process at once if possible
2. If you have a lot of duplicate strings, use String.intern() on them before putting them into the HashMap
3. Use the HashMap(int initialCapacity, float loadFactor) constructor to tune for your case

Use hibernate withSession and flush session after x number of save operation. Hibernate session atmost cache 20000-25000 domain object , so you need to flush session after every x amount of save opertaion . flushing session will remove the cache object from hibernate

查看更多
登录 后发表回答