问题描述
我在Guice的Web应用程序中有Quartz调度程序。我按照的代码进行了操作。一切正常,但我无法弄清楚如何关闭调度程序。我的上下文监听器如下所示:
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());
}
}
Quartz模块如下所示:
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?
推荐答案
您可以使用。
当您的wep-app停止时,应用服务器将调用 contextDestroyed()
。
The app server will call the contextDestroyed()
when your wep-app is stopped.
这将让您有时间在 QuartzModule上调用必需品
(在contextDestroyed()方法内) 就在网络应用停止之前。
This will give you time to call the necessaries on your QuartzModule
(inside the contextDestroyed() method) just before the web-app stops.
请记住添加< listener>
您的网络应用的 web.xml 中的标记。
Just remember to add the <listener>
tags in the web.xml of your web-app.
这篇关于关闭Quartz调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!