在Tomcat7.0.2中使用DBCP的BasicDataSource有时会报内存泄漏,信息如下:

2010-10-22 21:37:41 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/Spring_2500_UserRegister_SSH] registered the JBDC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

解决办法:
public class XBasicDataSource extends BasicDataSource {
    @Override
    
public synchronized void close() throws SQLException {
        DriverManager.deregisterDriver(DriverManager.getDriver(url));
        
super.close();
    }

}
强制注销JDBC驱动才不提示这个。

在开发模式下,热部署就会存在这种情况。奇怪的是,我按以前情况修改了,热部署还是一样,难道在开发模式下,热部署就一定会存在内存泄漏?

详细文档请见https://issues.apache.org/jira/browse/DBCP-332