在启动时集成tomcat和Quartz调度程序

编程入门 行业动态 更新时间:2024-10-28 08:19:36
本文介绍了在启动时集成tomcat和Quartz调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

  • 我可以通过带有加载的servlet来做到这一点-startup web.xml 中的描述符,用于启动调度程序并调度servlet中的作业。
  • 可以使用 ContextListener 来完成(这对我来说听起来比1更好)。这可能是一种干净的方法来启动 contextInitialized 方法中的调度程序,并关闭 contextDestroyed 方法中的调度程序。
  • 使用MBean描述符。我开发了一个MBean,它将在服务器启动mbeans-descriptor.xml文件时启动。
  • 对我来说,看起来第二种方法更好。第三个可能不是一个好主意,因为它显然不是由jconsole监视的MBean。我的目的是启动调度程序并在tomcat停止时停止它。 有没有更好更清洁的方法呢?

    解决方案

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

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

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

    www.quartz-scheduler/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 -

  • 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.
  • 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.
  • 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:

    quartz-scheduler/documentation/quartz-2.x/cookbook/ServletInitScheduler

    and

    www.quartz-scheduler/api/2.0.0/

    for details.

    更多推荐

    在启动时集成tomcat和Quartz调度程序

    本文发布于:2023-11-24 04:01:59,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1623899.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:启动时   程序   tomcat   Quartz

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!