关闭Quartz调度程序

时间:2010-10-09 20:42:35

标签: java quartz-scheduler guice servlets

我在Guice的Web应用程序中有Quartz调度程序。我按照找到的代码here。一切正常,但我无法弄清楚如何关闭调度程序。我的上下文监听器如下所示:

public class MyAppContextListener extends GuiceServletContextListener{

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new QuartzModule(), new MyAppServletModule());
    }
}

Quartz模块看起来像这样:

public class QuartzModule extends AbstractModule {

@Override
protected void configure() {
    bind(SchedulerFactory.class).to(StdSchedulerFactory.class).in(Scopes.SINGLETON);
    bind(GuiceJobFactory.class).in(Scopes.SINGLETON);
    bind(Quartz.class).in(Scopes.SINGLETON);
}

在停止或取消部署应用程序时关闭调度程序的最佳方法是什么?

1 个答案:

答案 0 :(得分:3)

您可以使用ServletContextListener

当您的wep-app停止时,应用服务器会调用contextDestroyed()

这将让您有时间在网络应用停止之前,在QuartzModule (在contextDestroyed()方法内) 中调用必需品。< / p>

请记住在您的网络应用的 web.xml 中添加<listener>标记。

相关问题