3

I have a problem with some thread and memory leak...In the log of my Tomcat7 I found this lines about my grails application:

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.

and more of those... The problem is that I think that all those threads are created in a part of the application developed from a 3th party JAR which I don't have the source and I can't modify by myself.

Is there a way to solve it, or at least to understand what is not going well?

thanks

4

2 回答 2

4

第一行表示 MySQL JDBC 驱动程序中的错误。看起来它已在 5.1.6 中修复 - 请参阅http://bugs.mysql.com/bug.php?id=36565因此您可以尝试用http://dev.mysql.com/downloads中的最新版本替换 jar /连接器/j/

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

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

于 2012-05-16T11:57:00.190 回答
2

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

  • 我创建了一个ServletContextListener
  • 在该contextDestroyed方法中,通过使用反射,我调用了 DataSource 的 close 方法 - 在我的情况下,它似乎适用于 c3p0 和 DBCP
  • 对于 c3p0,我认为还应该调用静态方法 com.mchange.v2.c3p0.DataSources.destroy(dataSource);
于 2012-07-27T11:36:10.667 回答