tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Class reload and database connections
Date Fri, 09 Nov 2001 17:00:40 GMT


On Fri, 9 Nov 2001, David Bell wrote:

> Date: Fri, 9 Nov 2001 15:56:52 -0000
> From: David Bell <david.bell@ioko365.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: Class reload and database connections
>
> I am currently porting a web application from JServ to Tomcat 4.0.1
> and have run into a problem.
>
> The application maintains a database connection pool in a singleton
> utility class. When I change another class the auto reload eventually
> picks this up but this class goes and creates a new connection pool
> even though the old one has not been destroyed.
>

It sounds like you might want to destroy the old connection pool when the
application is reloaded (or when Tomcat is shut down).

An easy way to deal with this is to use the new "ServletContextListener"
APIs from Servlet 2.3 (see the spec at
<http://java.sun.com/products/servlet/download.html> for more info).
Basically, you create a class that implements ServletContextListener, and
register it in the web.xml file.  Then, the contextInitialzed() method
gets called when the application is started (either because you started
Tomcat normally or after a restart), and contextDestroyed() is called when
the app is shut down (or before a reload).

Create your connection pool in the contextInitialized() method, and close
it in contextDestroyed().

> The upshot is that the number of connections steadily grows while I am
> developing until the database gives up.
>
> Under JServ I understood that when a class was changed the whole zone
> was reloaded. What goes on with Tomcat when it reloads? Are there
> issues of threading here?
>

This is still true -- but there's a couple of things that might be going
on:

* Where is your connection pool class loaded from?  If it's
  in the "lib" directory, those classes do *not* get reloaded.

* Did your application ever close the old connections?

> (I am running on Solaris 2.8 with JDK 1.2.2)
>
> David Bell
> mailto:David.Bell@ioko365.com
>

Craig



--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message