项目需要对Tomcat下部署的context做reload,实际效果很差,期间发生PermGen内存溢出。
记得Tomcat6.0.24开始提供内存溢出提示:
http://wiki.apache.org/tomcat/MemoryLeakProtection
6.0.24开始提供溢出log
6.0.25开始在manager提供 Find Leaks 按钮 —— 其实这按钮意义不大,有价值的信息全在log里了
果断升级,从tomcat6.0.16升到6.0.29,测试果然发现内存泄漏警告
其中一条:
严重: The web application [/batch] created a ThreadLocal with key of type [null] (value [ch.qos.logback.core.UnsynchronizedAppenderBase$1@ca95d6]) and a value of type [java.lang.Boolean] (value [false]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
使用的logback版本0.9.21,存在ThreadLocal泄漏,查看最新版本的logback专门提示修复了bug
http://logback.qos.ch/news.html 9.0.26版本fix
http://jira.qos.ch/browse/LBCLASSIC-183 bug描述
升级后问题解决
JDBC的泄漏Tomcat会自动解决,虽然有警告,可以无视(同时Tomcat log的错字...)
严重: The web application [/batch] registered the JBDC 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.
目前遗留了DBCP(Ver 1.3 1.4都存在)的泄漏问题
https://issues.apache.org/jira/browse/DBCP-332
声称在1.3.1、1.4.1版本修复,不知何时release
总结:
从版本号上也能看出来,这功能不怎么重要,tomcat团队也没好意思做多少推广,JreMemoryLeakPreventionListener实现的内存泄漏检测还停留在reload级别上,实际运行的泄漏依然需要profile调试。