【问题标题】:Tomcat/Grails memory leaksTomcat/Grails 内存泄漏
【发布时间】:2014-06-19 17:14:49
【问题描述】:

每次我通过 grails 应用程序取消部署时,我都会在 catalina.out 日志中看到以下内容:

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.

我实际上看到了 100 多个休眠模式。似乎存在与 Grails 2.0 中修复的域类相关的内存泄漏,但我使用的是 2.35。如果这很可能是我的应用程序中导致这些泄漏的原因,我想知道如何解决它们。谢谢...

【问题讨论】:

  • 你使用 Grails Quartz 插件还是 Quartz?
  • 不@VitaliiSamolovskikh,我们不使用石英。作为一种解决方法,我在每次部署时都重新启动 tomcat(而不是允许 tomcat 重新部署我的 grails 应用程序),但我仍然在日志中看到这些条目。
  • 面临同样的问题,我没有使用石英插件。
  • 您找到解决方案了吗?有很多人遇到这些问题,但遗憾的是到目前为止似乎没有解决方案。

标签: hibernate grails memory-leaks tomcat7


【解决方案1】:

您的域中是否定义了任何 HashMap 类型的字段。您正在 bootstrap.groovy 中填充该域?

有一些使用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

在 x 次保存操作后使用休眠 withSession 和刷新会话。休眠会话最多缓存 20000-25000 个域对象,因此您需要在每 x 次保存操作后刷新会话。刷新会话将从休眠中删除缓存对象

【讨论】:

  • 我相信我的一个域类中可能有一个枚举集,但我没有在我的引导程序中进行任何数据填充
猜你喜欢
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 2014-04-12
  • 1970-01-01
  • 2012-08-20
  • 2012-08-06
相关资源
最近更新 更多