3

在 Glassfish 中部署/取消部署/重新部署 JEE5 应用程序时,如何自动触发 Java 函数以停止 Quartz 调度程序作业。

4

2 回答 2

5

实施ServletContextListener并挂上contextDestroyed().

基本示例:

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.
    }

}

并将其注册为<listener>in web.xml

<listener>
    <listener-class>com.example.Config</listener-class>
</listener>
于 2009-12-07T19:20:09.643 回答
1

进入 JAVA EE-6+ 后,使用 @WebListener 注释一个类并在该类上实现 ServletContextListener 以获得关闭通知。无需处理 web.xml。看这里

于 2013-10-01T16:05:41.547 回答