我们正在使用tomcat-7.0.33.
Spring 3.0.1和JPA使用tomcat JNDI数据源.使用ojdbc6.jar(最新)后端的Oracle 10g.
当我们尝试取消部署应用程序时,一些Oracle类似乎正在泄漏.我在使用旧的ojdbc14.jar驱动程序时没有看到这一点,但我们无法使用这些驱动程序,因为我们正在迁移到需要更新驱动程序的Oracle 11g.我猜这是Oracle驱动程序中的一个错误?有什么办法可以清理这些资源吗?我试过关闭数据库连接池和其他东西无济于事……
不使用Tomcat的连接池会更好吗?我们宁愿让服务器连接到数据库,但如果有必要,我们可以自己做…
Server控制台显示:
17505 INFO org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean – Closing JPA EntityManagerFactory for persistence unit ‘myManager’
17515 INFO org.apache.tiles.access.TilesAccess – Removing TilesContext for context: org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext
Dec 06,2012 6:41:29 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/myApp] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@1468544]) and a value of type [java.lang.Class] (value [class oracle.sql.AnyDataFactory]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dec 06,2012 6:41:29 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/myApp] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@d73b31]) and a value of type [java.lang.Class] (value [class oracle.sql.TypeDescriptorFactory]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dec 06,2012 6:41:29 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/myApp] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@13aae39]) and a value of type [java.lang.Class] (value [class oracle.sql.TypeDescriptorFactory]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dec 06,2012 6:41:29 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/myApp] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@18443b1]) and a value of type [java.lang.Class] (value [class oracle.sql.AnyDataFactory]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dec 06,2012 6:41:34 PM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/myApp]
我已经尝试添加ContextListener手动关闭我们的DBCP连接,但这没有帮助.
InitialContext initial = new InitialContext();
DataSource ds = (DataSource) initial.lookup("java:/comp/env/jdbc/myDS");
if (ds.getConnection() == null) {
throw new RuntimeException("I failed to find the datasource");
}
LOG.debug("Found datasource. Closing...");
BasicDataSource bds = (BasicDataSource) ds;
bds.close();
想出了问题…… Toni提出了一个很好的建议(但取消注册驱动程序意味着当应用程序重新加载驱动程序时不再可用!).
在我们的例子中,我们意外地将ojdbc6.jar与我们的Web应用程序AND包含在Tomcat / lib目录中.这可能导致Tomcat使用我们的类加载器来创建对象.因此,当我们的应用程序被卸载时,Tomcat的DBCP池仍然在我们的应用程序中有类的打开句柄.
从我们的WEB-INF / lib中删除ojdbc6.jar解决了这个问题.