tags:

views:

38

answers:

3

We run our web application wehre we start some Threads for background work and also Quartz. When I try to shutdown tomcat(using shell script on linux), I always get the error saying failed to shutdown tomcat due to daemon threads and Quartz threads. We have tried different ways to shutdown our threads (exit out of run method) but we rely on few static variables of a class to do this which become null by the time my shut down listener gets a callback

Is there a standard approach to shut down tomcat for such a scenario?

+2  A: 

Not the answer, but good to know:

The JVM doesn't offer any shutdown guarantees for daemon threads. They just stop. No finally, no garbage collection, nothing.

extraneon
+2  A: 

And now for the possible answer (if you use Spring), check out this thread. If you use Spring you can add an explicit destroy clause in your spring config for Quartz so it can shutdown cleanly.

Otherwise a Servlet listener (I think the ServletContext listener, but it has been a while...) can detect shutdown and you can manually shutdown Quartz.

extraneon
A: 

FInally I was able to get it. The problem was not tomcat but the way our application sued to Initialize. We moved initialization of our application (class which starts these threads) into a listener as as per the servlet spec, servlets are loaded last and unloaded first where listeners are loaded first and unloaded last from the server. Spring link given by extraneon was very helpful

Fazal