You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tom Cat <to...@gmail.com> on 2008/09/13 01:13:14 UTC
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
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat shutdown event
Posted by Konstantin Kolinko <kn...@gmail.com>.
2008/9/13 Tom Cat <to...@gmail.com>:
>
> I have a servlet 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?
>
You may implement a
o.a.c.LifecycleListener
see
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
Also, the Servlet spec provides the ServletContextListener interface.
Also, Java has support for JVM shutdown hooks.
Also, if you start your own thread you may want to call
Thread.setDaemon(true), because non-demon (default) threads
prevent JVM from shutdown.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat shutdown event
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
To whom it may concern,
Tom Cat wrote:
> 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.
You need to define your thread as a "daemon" thread and it won't stop
the JVM from shutting down.
Don't worry about all this Tomcat lifecycle and servlet init/destroy
stuff from the other responses.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkjQItIACgkQ9CaO5/Lv0PA2wgCfd7Z/9/pbC/zdb9LmludWZosP
LQEAniHg9oFR1KwC11w5w1XcRV2JMs49
=tB3N
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat shutdown event
Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
----- Original Message -----
From: "Tom Cat" <to...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
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...
init
destroy
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
out...
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
doing....
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...
---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org