我们正在使用tomcat-7.0.33。Spring 3.0.1和JPA使用tomcat JNDI数据源。使用ojdbc6.jar(最新)在后端使用Oracle 10g。
当我们尝试取消部署应用程序时,某些Oracle类似乎正在泄漏。使用较旧的ojdbc14.jar驱动程序时,我看不到此信息,但是由于要迁移到需要较新驱动程序的Oracle 11g,我们无法使用它们。我猜这是Oracle驱动程序中的错误吗?我有什么办法可以清理这些资源?我试图关闭数据库连接池和其他东西都无济于事…
我最好不使用Tomcat的连接池吗?我们希望服务器连接到数据库,但是如果需要,我们可以自己做…
服务器控制台显示:
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应用程序一起包含在Tomcat / lib目录中。这很可能导致Tomcat使用我们的类加载器来创建对象。因此,当我们的应用程序被卸载时,Tomcat的DBCP池仍然具有我们应用程序中类的打开句柄。
从我们的WEB-INF / lib中删除ojdbc6.jar解决了该问题。