tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johnny Kewl" <>
Subject Re: Tomcat shutdown event
Date Sat, 13 Sep 2008 06:34:03 GMT

----- Original Message ----- 
From: "Tom Cat" <>
To: "Tomcat Users List" <>
Sent: Saturday, September 13, 2008 1:13 AM
Subject: Tomcat shutdown event

> Hello,
> I have a servelet spawn a thread that should run until tomcat is
> shutdown. The problem is, when Tomcat is shut down, the thread keeps
> running.
> Does Tomcat have a shutdown event that I could use to trigger the
> thread destruction? If not, is there any graceful way of handling
> this?
> Thanks

A servlet has two overrides that you may find useful...


One is called at the very beginning of life and one at the end...

If the thread is active, one could poll a
mustIContinue flag... and if Destroy set that false the thread falls thru. 
after cleaning up...
Killing threads is not a thing to do ever... idea should be for the 
"service" to clean up and end itself.

If its a waiting thread... then you also have to wake it up so it can get 

Alot to do with design...

On some systems...a third party engine, like an indexer can take a long time 
to finish and dont expose any controls, like interrupt me now.... engines 
like that are a problem....

I havent experienced any problems with letting a service thread run "after 
tomcat", in my case it is indexing engines that may run for 2 or 3 mins 
after tc has said goodbye... thats ok... but it depends on what you 

If your "service" should be ending... its a batch... and the batch is 
actually completing... but TC is cleaning up nicely... thats a bug, refs 
holding somewhere... you got to find em ;)

Anyway dont bang it closed...
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action :

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message