Organizational Research By

Surprising Reserch Topic

why do connections persist when i undeploy a webapp using the tomcat 7 jdbc conn

why do connections persist when i undeploy a webapp using the tomcat 7 jdbc conn  using -'tomcat,jdbc,connection-pooling,tomcat7'

I've got a minimal Spring webapp deployed to Tomcat 7.0.22 - it consists of a couple of pages, a controller, a service, and a DAO which has one method that runs a SELECT query.

The webapp is configured to use the new Tomcat JDBC connection pool - here is the resource configuration in the webapp's context.xml:

<Resource name="jdbc/myDB"
          url="jdbc:oracle:thin:@blah blah"
          validationQuery="select 1 from dual"
          minEvictableIdleTimeMillis="60000" />

When I deploy the webapp I see 5 connections appear (querying v$session from SQL Developer).  When I undeploy the webapp the connections persist (in state WAITING).  Each time I redeploy my webapp, 5 new connections show up.

It appears the pool is still hanging around - and the "Find Leaks" button on Tomcat's manager app tells me the app is leaking memory.

How do I get rid of the pool when the webapp is undeployed?

asked Oct 19, 2015 by sumit_jaiswalmca
0 votes

Related Hot Questions

3 Answers

0 votes

The problem was self-inflicted (as most are). My data source was configured in my webapp's web.xml and I was referencing it via JNDI. I now create my data source as shown in the Spring reference doc (section 13.3.1) and the destroy method takes care of closing the data source and pool.

If I'd been required to stick with a JNDI data source I would have had to close out the data source in a class that implements ServletContextListener, in the contextDestroyed method.

answered Oct 19, 2015 by rajeshujade
0 votes

This is a behaviour reported in Apache Tomcat bugzilla, Reference:

It has been corrected from Tomcat 7.0.11. Which version of Tomcat have you been using ?

If you use create the datasource as described in the Spring reference at"application level", you would a little overhead when it comes to administration tasks if you have a lot of applications and many servers.

answered Oct 19, 2015 by rajeevr642
0 votes

I had the same problem and I could not use spring so I used a org.apache.tomcat.jdbc.pool.DataSourceProxy to close a Tomcat Datasource. This API provides you with functionality not yet implemented JDK DataSource interface.

DataSourceProxy myDataSource = (DataSourceProxy) myDataSource;
  • Also using factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" and a ServletListener contextDestroyed method.
answered Oct 19, 2015 by mca.agarwal