gpt4 book ai didi

java - Oracle 驱动程序内存泄漏 - Tomcat

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:02:52 24 4
gpt4 key购买 nike

我们使用的是 tomcat-7.0.33。 Spring 3.0.1 和 JPA 使用 tomcat JNDI 数据源。 Oracle 10g 在后端使用 ojdbc6.jar(最新)。

当我们尝试取消部署应用程序时,某些 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$SpringWildcardServletTilesApplicationContextDec 06, 2012 6:41:29 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaksSEVERE: 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 checkThreadLocalMapForLeaksSEVERE: 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 checkThreadLocalMapForLeaksSEVERE: 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 checkThreadLocalMapForLeaksSEVERE: 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 deleteRedeployResourcesINFO: 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 解决了这个问题。

关于java - Oracle 驱动程序内存泄漏 - Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13754858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com