Oracle驱动程序内存泄漏 - Tomcat [英] Oracle driver memory leak - Tomcat

查看:924
本文介绍了Oracle驱动程序内存泄漏 - Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We're using tomcat-7.0.33. Spring 3.0.1 and JPA using a tomcat JNDI datasource. Oracle 10g on the backend using ojdbc6.jar (latest).

当我们尝试取消部署应用程序时,一些Oracle类似乎正在泄漏。在使用较旧的ojdbc14.jar驱动程序时我没有看到这一点,但我们无法使用这些驱动程序,因为我们正在迁移到需要更新驱动程序的Oracle 11g。我猜这是Oracle驱动程序中的一个错误?有什么办法可以清理这些资源吗?我试过关闭数据库连接池和其他东西无济于事...

When we try to undeploy the application some Oracle classes seem to be leaking. I don't see this when using the older ojdbc14.jar drivers but we can't use those as we're migrating to Oracle 11g which requires the newer drivers. I'm guessing this is a bug in the Oracle drivers? Is there anything I can do to clean these resources up? I've tried closing the database connection pool and other things to no avail...

我最好不要使用Tomcat的连接池吗?我们宁愿让服务器连接到数据库,但我们可以在必要时自己做...

Would I be better off not using Tomcat's connection pool? We'd rather have the server connecting to the database but we could do our own if necessary...

服务器控制台显示:


17505 INFO org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - 关闭持久性单元'myManager'的JPA EntityManagerFactory
17515 INFO org.apache.tiles.access.TilesAccess - 删除TilesContext context:org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory $ SpringWildcardServletTilesApplicationContext
12月06,2012 6:41:29 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE:Web应用程序[/ myApp]创建了一个ThreadLocal,其键为[java.lang.ThreadLocal](值为[java.lang.ThreadLocal@1468544]),类型为[java.lang.Class](value [class oracle.sql]。 AnyDataFactory])但在Web应用程序停止时无法将其删除。线程将随着时间的推移而更新,以尝试避免可能的内存泄漏。
2012年12月6日下午6:41:29 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
严重:Web应用程序[/ myApp]创建了一个类型为[java.lang.ThreadLocal]的密钥的ThreadLocal ](值[java.lang.ThreadLocal@d73b31])和类型[java.lang.Class](值[类oracle.sql.TypeDescriptorFactory])的值但在Web应用程序停止时无法将其删除。线程将随着时间的推移而更新,以尝试避免可能的内存泄漏。
2012年12月6日下午6:41:29 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
严重:Web应用程序[/ myApp]创建了一个类型为[java.lang.ThreadLocal]的密钥的ThreadLocal ](值[java.lang.ThreadLocal@13​​aae39])和类型[java.lang.Class](值[类oracle.sql.TypeDescriptorFactory])的值,但在Web应用程序停止时无法将其删除。线程将随着时间的推移而更新,以尝试避免可能的内存泄漏。
2012年12月6日下午6:41:29 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
严重:Web应用程序[/ myApp]创建了一个类型为[java.lang.ThreadLocal]的密钥的ThreadLocal ](值[java.lang.ThreadLocal@18443b1])和类型[java.lang.Class](值[类oracle.sql.AnyDataFactory])但在Web应用程序停止时无法删除它。线程将随着时间的推移而更新,以尝试避免可能的内存泄漏。
12月06,2012 6:41:34 PM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO:取消部署上下文[/ myApp]
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连接,但这没有帮助。

I have tried adding a ContextListener to close our DBCP connection manually but that didn't help.

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很好建议(但取消注册驱动程序意味着当应用程序重新加载驱动程序时不再可用!)。

Figured out the issue... Toni had a good suggestion (but de-registering the driver meant that when the app reloaded the driver was no longer available!).

在我们的案例中,我们意外地将ojdbc6.jar包括在内Web应用程序AND在Tomcat / lib目录中。这可能导致Tomcat使用我们的类加载器来创建对象。因此,当我们的应用程序被卸载时,Tomcat的DBCP池仍然在我们的应用程序中有类的开放句柄。

In our case we were accidentally including ojdbc6.jar with our web app AND in the Tomcat/lib directory. This pressumably caused Tomcat to use our classloader to create objects. Thus when our application was being unloaded Tomcat's DBCP pool still had open handles to classes in our application.

从我们的WEB-INF / lib中删除ojdbc6.jar解决了这个问题。

Removing ojdbc6.jar from our WEB-INF/lib solved the problem.

这篇关于Oracle驱动程序内存泄漏 - Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆