以下为tomcat7的提示信息:
The web application [] 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.
The web application [] 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
如果热部署的时候不注意以上的信息引起的内存泄露,多次部署后会出现内存溢出OutOfMemory错误。
解决办法:
创建自己的Listener后
public void contextDestroyed(ServletContextEvent servletContextEvent) {
//mysql线程池泄露,关闭线程
try {
com.mysql.jdbc.AbandonedConnectionCleanupThread.shutdown();
} catch (Throwable t) {
}
//注销database驱动
Enumeration enumeration = DriverManager.getDrivers();
while (enumeration.hasMoreElements()) {
try {
DriverManager.deregisterDriver(enumeration.nextElement());
} catch (Throwable t) {
}
}
}