Trigger function when Undeploying application

谁说我不能喝 提交于 2020-01-01 16:59:57

问题


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


回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/1862242/trigger-function-when-undeploying-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!