tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodrigo Ruiz <rr...@gridsystems.com>
Subject Re: detecting the shutdown of tomcat in a servlet
Date Wed, 28 Jul 2004 10:21:23 GMT
There is more than one way :-)

- From within a servlet, add a shutdown hook with 
Runtime.getRuntim().addShutdownHook()
- Create a ServletContextListener, and implement the clean stop of your 
daemon in the listener contextDestroyed() method
- Create an initialization servlet, and implement the clean stop in its 
destroy() method

and probably a few more if you use specific Tomcat classes.

I would not use the first option unless really necessary, as it seems to 
me a too much "low level solution".
My favourite is the second option, as this is what 
ServletContextListeners are for. You could start and stop the thread 
from this listener.

The second and third options will perform the thread stop when the 
context or the container are shut down. This includes a context stop 
from the admin webapp. Whether this is good or bad for your purposes 
depends on the actions you need to perform. I suppose you do not want 
your thread to keep running if you stop the webapp, because restarting 
the webapp would lead to have two daemon threads :-)

HTH,
Rodrigo Ruiz

STOCKHOLM, Raymond wrote:

>In my tomcat 4.1.30n, I have a webapp in which a deamon Thread (started automatically)

>is scheduled to send automatic mails every morning.
>
>I would like to make a clean stop of my deamon when tomcat shutdowns.
>
>How can I detect that tomcat is shuting down ?
>
>
>Raymond Stockholm
>Aubay Luxembourg
>51, Rue de Strasbourg
>L-2561 LUXEMBOURG
>Tel : +352 29 92 50 31
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>  
>


-- 
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.727 / Virus Database: 482 - Release Date: 27/07/2004


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message