2012-05-16 194 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);