开发者

Quartz on a webapp - scheduler does not stop

I have a webapp running on weblogic that runs a S开发者_JS百科cheduler on a ServletContextListener.

The problem is the scheduler runs indefinitely, so even if i stop the webapp or redeploy the scheduler keeps running.

I should be able to stop the scheduler on contextDestroyed, but I don't have the instance. I've seen a couple of websites recommending this aproach to the problem, but they all have shedulers running a defined number of times.


Quartz comes with a servlet specifically for starting & stopping the scheduler on application startup and shutdown simply add the following to your web.xml:

<servlet> 
  <servlet-name>QuartzInitializer</servlet-name> 
  <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>


If you want to shutdown without waiting for the executing jobs to finish use:

scheduler.shutdown(false);

Check this page for more info.


Upon application shutdown you must call

        scheduler.shutdown();

Sometimes you have to do a Thread.sleep(1000); to let it shut down properly aswell.

Do this in a ContextLoad listener or other shutdown hook that you have.

To get the instance depends on how you have set up quartz, but the default scheduler can be obtained like this:

        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

See http://www.quartz-scheduler.org/docs/1.x/quick_start_guide.html for more information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜