Isn't this the difference between daemon-threads and non-daemon-threads?
The JVM waits on exit until all non-daemon-threads are finished (or was is for
daemon-threads, see the docs).
Ronald.
On Mon Mar 20 08:37:52 CET 2006 Tomcat Users List <users@tomcat.apache.org>
wrote:
Hello,
I had the same question in my mind some time ago. I have a web application
which creates a timer in a context listener init(), which wakes up in 30seconds
or so, and destroys the timer in context listener destroy(). It should complete
its processing before server stops, so I did some experiments.
If I use Timer and TimerTask in J2SE, stopping the application does not wait
timer task to complete if its running (it is a behaviour we can guess), however
timer task is not killed and it is completed after context listener destroy()
finishes. The situation is different if you stop tomcat, where timer and its
associated task if its running is killed immediately. In windows, tomcat
monitor has a timeout parameter, I think this adjust the time it should wait
for all user threads to die. I dont know if there is such a parameter in *nix
environments.
Since I need to wait for Task to complete, I do it by putting some
synchronization controls when destroying timer. This solves the problem if you
only stop the application. However, stopping tomcat still kills the thread in
windows environment, so I adjust the timeout parameter to a reasonable value
(this may be an issue on windows platforms only, I remember stopping tomcat in
linux waits for threads if you do some synchronization). Later, I moved to
Quartz framework which has a stop function which waits for task to complete.
Surprisingly, stopping tomcat also waits for timer tasks (jobs) if I use Quartz
(even with zero timeout on windows). So, it is clear I miss a big point when I
use my own Timer/TimerTask and thread controls.
I did those experiments some time ago, some points may be wrong or out of date.
You can easily try it by yourself.
Best regards,
Mete
-----Original Message-----
From: Clemens Eisserer [mailto:[EMAIL PROTECTED]
Sent: Saturday, March 18, 2006 8:32 PM
To: users@tomcat.apache.org
Subject: Tomcat and Threads
Hello,
I've created a servlet wich creates some threads for doing background
stuff. Till now I never worried about these thread since I was
runnning this servlet only on my own servers.
However now I subscribed to a servlet-hosting service which uses a
shared tomcat enviroment.
How does tomcat handle these threads?
Will they be destroyed by tomcat as soon as I click "stop" in Tomcat's
application manager or will I have to take care about them?
Thank you in advance, lg Clemens
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]