如何解决内存泄漏问题?(How to solve memory leak problems?)

2019-07-29 09:40发布

我有一些线程和内存泄漏问题...在日志我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开发的应用程序的一部分创建,我不能由我自己修改。

是否有解决这个问题的一种方式,或至少理解什么是不顺利?

谢谢

Answer 1:

第一行表示MySQL JDBC驱动程序的bug。 看起来像它被固定在5.1.6 -见http://bugs.mysql.com/bug.php?id=36565所以你可以尝试从最新的替换罐子http://dev.mysql.com/downloads /连接器/ J /

其他行表示已启动,并且应用程序停止时没有停止线程池。 这实际上只能通过修改第三方jar的源代码是固定的,如果这是问题的所在。

如果可能的话,你可以尝试暂时消除了第三方jar,看看问题是否会消失。



Answer 2:

对于线程池的问题,解决方法我用了(这似乎工作)是:

  • 我创建了一个ServletContextListener
  • contextDestroyed方法,通过使用反射,我称之为数据源的close方法-在我的情况,似乎与C3P0和DBCP工作
  • 为C3P0我觉得一个也应该调用静态方法com.mchange.v2.c3p0.DataSources.destroy (数据源);


文章来源: How to solve memory leak problems?