jjczopek
jjczopek

Reputation: 3379

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 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?

Upvotes: 2

Views: 3469

Answers (1)

Koekiebox
Koekiebox

Reputation: 5973

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.

Upvotes: 3

Related Questions