关闭 Quartz 调度程序

发布于 2024-09-26 18:55:10 字数 771 浏览 6 评论 0原文

我的网络应用程序中有 Quartz 调度程序和 Guice。我按照此处找到的代码进行操作。一切正常,但我不知道如何关闭调度程序。我的上下文侦听器如下所示:

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椵侞 2024-10-03 18:55:10

您可以使用 ServletContextListener

当您的 wep 应用程序停止时,应用程序服务器将调用 contextDestroyed()

这将使您有时间在网络应用程序停止之前调用 QuartzModule 上的必要操作(在 contextDestroyed() 方法内)

只需记住在网络应用的 web.xml 中添加 标签即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文