2012-05-16 155 views
3

我有一些线程和内存泄漏问题...在日志我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开发的应用程序的一部分中创建的,我没有源代码,我无法自行修改。

有没有办法解决这个问题,或者至少了解什么不好?

谢谢

+0

仙界有同样的问题一次,并没有真正找到一个解决方案,但它仍然保持正常工作。任何人都知道如果剥离战争文件大小会有什么影响? – marko

回答

4

第一行指出MySQL JDBC驱动程序中的一个错误。看起来像它被固定在5.1.6 - 见http://bugs.mysql.com/bug.php?id=36565所以你可以尝试从http://dev.mysql.com/downloads/connector/j/

了最新更换的jar其他行表示已启动,并且应用程序停止时没有停止线程池。 这真的只能通过修改第三方jar的源代码来解决,如果这是问题所在。

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

+0

干杯人!但是有没有一些工具可以用来找出问题的所在?我也不知道哪个组件创建了ThreadPool,或者可以帮助我找到源代码中应该更改的内容? – rascio

+0

我更新了最新的mysql jdbc驱动程序,但它没有解决问题。我仍然得到相同的MySql错误。 – ishan

+0

[MYSQL bug](http://bugs.mysql.com/bug.php?id=36565)解决方案:将mysql更新到5.1.27或更高版本 –

2

对于线程池的问题,我使用的溶液(和它似乎工作)为:

  • 我在contextDestroyed方法创建的ServletContextListener
  • ,通过使用反射,我调用Close方法数据源 - 在我的情况下,它似乎与c3p0和DBCP
  • c3p0我认为还应该调用静态方法 com.mchange.v2.c3p0.DataSources.destroy(dataSource);