关闭tomcat时提示memory leak警告解决办法

来源:互联网 发布:一直是正在准备windows 编辑:程序博客网 时间:2024/05/22 07:40

原文地址:http://blog.sina.com.cn/s/blog_81b86edf01014nrq.html


当我们关闭tomcat 或者redeploy project时, 仔细看的话,会有一些error跳出来。 这些是一些memory leak的问题,自tomcat 6.0.24以后tomcat增加的安全检测机制。

不要忽视这些问题,它可能会造成memory leak, 就是tomcat关闭以后,还有thread在跑。。。 这是非常不安全,并会对服务器的稳定造成很大影响的,下面是一些总结,工作时候发给同事的,没翻译,有需要的话就将就着看吧。

Overall, the reason for these alarms is from tomcat 6.0.24, there is a new function called memory leak protection. Refer to http://wiki.apache.org/tomcat/MemoryLeakProtection. This is a good function to make our applications and server better. And there is some suggestion in this web page. Include 'JDBC driver registration' problem.

The tomcat version below 6.0.24 does not alarm these memory leak problems, but the problem is exist. (I’ve tried tomcat 6.0.20).  There is memory leak (java process still running) but no alarm. It’s dangerous.

For JDBC driver registration problem.

SEVERE: The web application [/xxx] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Pls refer to http://bugs.mysql.com/bug.php?id=62170.

This is not regard as a bug(whatever, it has been forcibly unregistered already), we can unregister the driver by extends the lifecycle listener of spring framework. Such as org.springframework.web.context.ContextLoaderListener.  Override the contextDestroyed() function to unregister the JDBC driver.


For mysql connector 其他问题

When we are using mysql connector version 5.0.5 (mysql-connector-java-5.0.5.jar):

MySql Bug 1: The web application [/xxx] 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.

This bug was reported at version 5.1.6 and already been fixed already in the future version of MySql. Refer to http://bugs.mysql.com/bug.php?id=36565.

 

When we are using mysql connector version 5.1.22 (mysql-connector-java-5.1.22.jar):

MySql Bug 2: SEVERE: The web application [/xxx] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

This bug was reported at version 5.1.21 and its status is ‘IN PROGRESS’, it means it’s not fixed yet. Refer to http://bugs.mysql.com/bug.php?id=65909.

 

So I’m using the mysql connector 5.1.20 (mysql-connector-java-5.1.20.jar), everything looks good.