在启动时集成tomcat和Quartz调度程序 [英] Integration of tomcat and Quartz scheduler on startup

查看:482
本文介绍了在启动时集成tomcat和Quartz调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是tomcat 6.0版。我的要求是当tomcat启动时,我想启动一个 QuartzScheduler ,它会定期安排一些工作。我试图找出最好的方法来做到这一点。以下是我能想到的选项 -


  1. 我可以通过带有加载的servlet来做到这一点-startup web.xml 中的描述符,用于启动调度程序并调度servlet中的作业。

  2. 可以使用 ContextListener 来完成(这对我来说听起来比1更好)。这可能是一种干净的方法来启动 contextInitialized 方法中的调度程序,并关闭 contextDestroyed 方法中的调度程序。

  3. 使用MBean描述符。我开发了一个MBean,它将在服务器启动mbeans-descriptor.xml文件时启动。

对我来说,看起来第二种方法更好。第三个可能不是一个好主意,因为它显然不是由jconsole监视的MBean。我的目的是启动调度程序并在tomcat停止时停止它。
有没有更好更清洁的方法呢?

解决方案

我会推荐第二种方法,使用一个只用于启动某些服务的Servlet,虽然常见的用法,对我来说似乎很苛刻。



看来quartz已经为这个目的提供了一个ServletContextListener: / p>

http:/ /quartz-scheduler.org/documentation/quartz-2.x/cookbook/ServletInitScheduler





http://www.quartz-scheduler.org/api/2.0.0 /



了解详情。


I am using tomcat version 6.0. My requirement is that when tomcat starts up, I would like to start a QuartzScheduler which will schedule some jobs at a regular interval. I am trying to figure out the best possible way to do it. Here are the options that I could think of -

  1. I can do this via a servlet with "load-on-startup" descriptor in web.xml file to start the scheduler and schedule the jobs inside the servlet.
  2. Can be done using a ContextListener (this sounds a better approach to me than 1). This might be a clean approach to start the scheduler inside the contextInitialized method and shutdown the scheduler inside contextDestroyed method.
  3. Using a MBean-descriptor. I develop a MBean which will get started when the server starts up with mbeans-descriptor.xml file.

To me, it looks like second approach is better. Third one might not be a good idea as it is clearly not a MBean to be monitored by jconsole or so. My purpose is to start the scheduler and stop it when tomcat stops. Is there any better and cleaner way to do this ?

解决方案

I would recommend the second approach as well, using a Servlet that exists only to start up some service, while a common usage, seems hacky to me.

It appears that quartz already provides a ServletContextListener for this exact purpose:

http://quartz-scheduler.org/documentation/quartz-2.x/cookbook/ServletInitScheduler

and

http://www.quartz-scheduler.org/api/2.0.0/

for details.

这篇关于在启动时集成tomcat和Quartz调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆