如何解决内存泄漏问题?

时间:2012-05-16 08:55:51

标签: grails memory-leaks tomcat7

我遇到一些线程和内存泄漏的问题...在我的Tomcat7的日志中,我发现了关于我的grails应用程序的这一行:

SEVERE: The web application [/myApp] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-1] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-2] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-3] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-4] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-5] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-6] but has failed to stop it. This is very likely to create a memory leak.
May 16, 2012 6:02:10 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myApp] appears to have started a thread named [pool-63-thread-7] but has failed to stop it. This is very likely to create a memory leak.

以及更多...... 问题是我认为所有这些线程都是在从第三方JAR开发的应用程序的一部分中创建的,我没有源代码,我不能自己修改。

有没有办法解决它,或者至少要了解什么不顺利?

感谢

2 个答案:

答案 0 :(得分:4)

第一行表示MySQL JDBC驱动程序中的错误。看起来已在5.1.6中修复 - 请参阅http://bugs.mysql.com/bug.php?id=36565,以便您可以尝试使用http://dev.mysql.com/downloads/connector/j/中的最新内容替换jar

其他行表示已启动的ThreadPool,并且在应用程序停止时未停止。 这实际上只能通过修改第三方jar的源代码来解决,如果问题出在那里的话。

如果可能,您可以尝试暂时取消第三方jar,以查看问题是否消失。

答案 1 :(得分:2)

对于ThreadPool问题,我使用的解决方案(似乎有效)是:

  • 我创建了ServletContextListener
  • contextDestroyed方法中,通过使用反射,我调用DataSource的close方法 - 在我的例子中,它似乎与c3p0和DBCP一起使用
  • 对于c3p0我认为还应该调用静态方法 com.mchange.v2.c3p0.DataSources.destroy(dataSource);