tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Tomcat reload / classloader / connection pool
Date Wed, 03 Dec 2003 00:04:43 GMT

> The problems with Tomcat occur upon reload of the web app. The
> classloader reloads the whole app and all my DB connections get opened
> again. This wouldn't cause much pain if the existing connections were
> garbage collected i.e. finalized. This doesn't happen and after a couple
> of reloads the DB's max connections limit is reached...

Where do the class files for your DB connection pool live?

Is there a reason to use your own home-brewed CP other than bragging 
rights? :)

> First of all, why is this so?

This is likely because of the way you use the singleton. When you have a 
"singleton" (I use quotes because it's probably not a real singleton.... 
otherwise we would not be having this discussion) the static data is 
associated with the java.lang.Class object that gets created when your 
class is loaded. When the re-load occurs, that static data sticks 
around. The new classloader used for the new context loads a new copy of 
the "singleton" and they pile up over time. You need to shutdown the 
connection pool before the context dies.

> Second of all, how can I prevent this? Somehow listen for reloads and
> react appropriately?

Yes. Consider writing a ServletContextListener and "closing" the pool 
before the context goes down. It will be run when the new context comes 
up, too.

Check the documentation for javax.servlet.ServletContextListener

> Instead of deploying the framework JAR in the web app's WEB-INF/lib
> directory I could place somewhere in the regular CLASSPATH, but then all
> web apps would have access to the same ConnectionFactory :-((

Yes, and the problem would get worse.


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

View raw message