关闭 Quartz 调度程序
我的网络应用程序中有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 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.