commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikkel Heisterberg <>
Subject Re: [dbcp] Who/what calls BasicDataSource.close() in an application server (e.g. Tomcat)
Date Mon, 20 Feb 2006 09:56:36 GMT
So in other words the only way to obtain this kind of functionality easily 
would be a ServletContextListener which would get a reference to the 
connection pool from JNDI and then close the connection pool, or using 
some other (probably application server specific) life-cycle extension to 
make sure the connection pool is properly closed.


P.S.: I guess changing the connection pool from being instantiated and put 
in JNDI from a MBean instead of a Resource would also work.


Med venlig hilsen / Best regards, 

Mikkel Heisterberg

Wade Chandler <> 
19-02-2006 22:03
Please respond to
"Jakarta Commons Users List" <>

Jakarta Commons Users List <>

Re: [dbcp] Who/what calls BasicDataSource.close() in an application server 
(e.g. Tomcat)

--- Mikkel Heisterberg <>

> Hi there,
> I writing a custom connection pool for a project
> under Tomcat (written as 
> the dbcp using the javax.naming.spi.ObjectFactory
> interface). The 
> connection pool doesn't implement the
> javax.sql.DataSource interface. 
I suppose my answer to the rest of this is correct,
but I'm not sure what all you are doing here and if
there is some API to register an ObjectFactory within
Tomcat or not...none that I know of anyways as I don't
know of anything in the standards which permits this,
but that doesn't mean Tomcat doesn't have some support
itself.  I'm pretty sure it doesn't.

> For the connection pool I need some lifecycle
> management and in that 
> regard I was wondering how dbcp makes sure all the
> connections are closed 
> when the application server shuts down. I can see
> from the source that the 
> org.apache.commons.dbcp.BasicDataSource class has a
> close() method but I 
> cannot see how it is called upon server termination.
> Does any of you guys know?
> Mikkel Heisterberg
> Med venlig hilsen / Best regards, 
> Mikkel Heisterberg

You have to do this yourself using a listener within
your web application upon application shutdown. 
Obviously if the VM terminates abnormally this won't
matter and you'll have some connection creep, but
that's the way the cookie crumbles.  There is no
finalize method or reference listening code to clean
up if you don't specifically call close.  None that I
have ever seen.


To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message