开发者

Shutdown Quartz scheduler

I have Quartz scheduler in my web application with Guice. I followed code found here. Everything works fine, but I can't figure out how to shutdown scheduler. My context listener looks like this:

public class MyAppContextListener extends GuiceServletContextListener{

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new QuartzMo开发者_如何学Godule(), new MyAppServletModule());
    }
}

And Quartz module looks like this:

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);
}

What is the best way to shutdown scheduler when application is being stopped or undeployed?


You can make use of the ServletContextListener.

The app server will call the contextDestroyed() when your wep-app is stopped.

This will give you time to call the necessaries on your QuartzModule (inside the contextDestroyed() method) just before the web-app stops.

Just remember to add the <listener> tags in the web.xml of your web-app.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜