Java – Oracle driver memory leak – Tomcat

We are using tomcat-7.0 33. Spring 3.0. 1 and JPA use Tomcat JNDI data source Using ojdbc6 Oracle 10g. Jar (latest) backend

When we tried to undeploy the application, some Oracle seemed to be leaking I'm using the old Ojdbc14 Jar drivers, but we can't use these drivers because we are migrating to Oracle 11g. Jar, which needs to update the drivers I guess this is an error in the Oracle driver? Is there any way to clean up these resources? I tried to turn off the database connection pool and other things, but it didn't help

Would it be better not to use Tomcat's connection pool? We'd rather let the server connect to the database, but if necessary, we can do it ourselves

The server console displays:

I've tried to add a contextlistener and manually close our DBCP connection, but it doesn'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();

Solution

Came up with a problem... Toni made a good suggestion (but unregistering the driver means it's no longer available when the application reloads the driver!)

In our example, we accidentally put ojdbc6 Jar and our web application are contained in the Tomcat / lib directory This may cause Tomcat to use our classloader to create objects Therefore, when our application is unloaded, Tomcat's DBCP pool still has class open handles in our application

Remove ojdbc6.0 from our WEB-INF / lib Jar solves this problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>