Shutdown Quartz scheduler

天涯浪子 提交于 2019-12-22 18:15:32

问题


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 QuartzModule(), 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?


回答1:


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.



来源:https://stackoverflow.com/questions/3897807/shutdown-quartz-scheduler

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