开发者

Trigger function when Undeploying application

开发者 https://www.devze.com 2022-12-13 22:10 出处:网络
How do I automatically trigger Java function to stop Quartz scheduler jobs when I deploy/undeploy/redeploy JEE5 applicat开发者_JS百科ion in Glassfish. Implement ServletContextListener and hook on cont

How do I automatically trigger Java function to stop Quartz scheduler jobs when I deploy/undeploy/redeploy JEE5 applicat开发者_JS百科ion in Glassfish.


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>


Once you get to JAVA EE-6+, annotate a class with @WebListener and implement ServletContextListener on that class to get a shutdown notification. No need to deal with web.xml. See here

0

精彩评论

暂无评论...
验证码 换一张
取 消