views:

152

answers:

1

How do I automatically trigger Java function to stop Quartz scheduler jobs when I deploy/undeploy/redeploy JEE5 application in Glassfish.

+1  A: 

Implement ServletContextListener and hook on contextDestroyed().

Basic example:

public class Config implements ServletContextListener {
    public void contextInitialized(ServletContextEvent event) {
        // Write code here which should be executed on webapp startup.
    }
    public void contextDestroyed(ServletContextEvent event) {
        // Write code here which should be executed on webapp shutdown.
    }
}

and register it as a <listener> in web.xml.

<listener>
    <listener-class>com.example.Config</listener-class>
</listener>

Alternatively, you can also set them as daemon threads, so that they automagically stops whenever the JVM shuts down. I don't do Quartz (I just use java.util.TimerTask), but using the standard java.lang.Thread API you can use the setDaemon(true) for this. See if similar exist in Quartz.

BalusC