----- Original Message ----- 
From: "Anthony Eden" <[EMAIL PROTECTED]>
To: "'Tomcat Users List'" <[EMAIL PROTECTED]>
Sent: Tuesday, March 19, 2002 12:45 PM
Subject: RE: Creating threads from a servlet


> 
> 
> > -----Original Message-----
> > From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]] 
> > Sent: Tuesday, March 19, 2002 12:15 PM
> > To: Tomcat Users List; David Shanahan
> > Subject: Re: Creating threads from a servlet
> > 
> 
> <snip>
> 
> > 
> > A couple of notes about using your own threads in servlet containers:
> > 
> > - You must properly clean up your threads when the application
> >   is shut down.  If you don't, you are very likely to cause
> >   Tomcat to hang at shutdown time.
> 
> What exactly do you mean by "properly clean up your threads"?  I believe
> I am seeing this behavior in some of my systems and I am interested in
> fixing it.  Does this mean that the application must listen for some
> sort of shutdown notification?
> 
> Sincerely,
> Anthony Eden
>[...]


good emaol for you! :-)

Bo
Mar192002


> Hi all-
>
> I have a web application that uses some static resources to make them
> available to any class in the application.  Amongst these static
> resources is a home-brewed JDBC connection pool.  What I'm seeing is
> that with Tomcat 4, when I stop/start or reload an application from the
> manager app, it isn't freeing up these static resources.  I can see this
> because my memory utilization goes up about 5 megs every time I restart,
> whereas if I stop and restart the whole tomcat process, my memory stays
> the same.  Also the database starts yelling at me about too many
> applications simultaneously etc.
>
> How can I tell Tomcat to clean up these resources when it stops the
> application? What hook/mechanism is there?  Is there some sort of
> listener interface I can implement, similar in idea to an
> HttpSessionBindingEvent, to let me know when an application is shutting
> down so I can close all of the database connections?
>
> None of this was an issue in Tomcat 3.x because I had no choice but to
> shut down the entire tomcat instance!
>
> Any help greatly appreciated!  Thanks!
>
> Best regards,
>
> Richard
>

Doing this is exactly what the new application event listeners APIs (in
Servlet 2.3) are designed for.  You need to:

* Create a class that implements javax.servlet.ServletContextListener

* Register it (in web.xml> with a <listener> element

* In the contextInitialized() method, set up your connection pool

* In the contextDestroyed() method, gracefully clean up your
  connection pool.

Craig



--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to