Java Web 应用程序中的 Quartz 与 ScheduledExecutorService

发布于 2024-10-12 07:45:51 字数 863 浏览 4 评论 0 原文

对于当前在命令行上运行并使用 ScheduledExecutorService,我想编写一个简单的 Web 应用程序版本,在 Servlet 容器,例如 Apache Tomcat< /a> 或 Eclipse Jetty

我读过 Quartz 作为流行的 用于 Web 应用程序的作业调度程序。将此应用程序从 ScheduledExecutorService 移植到 Quartz 会更好吗(可能是因为更好的 servlet 容器集成)?

向应用程序添加另一个库依赖项不是问题,我对反对使用 ScheduledExecutorService 的技术原因感兴趣。

For a system monitoring Java application which currently runs on the command line and uses ScheduledExecutorService, I would like to write a simple web application version, to be run in a Servlet container like Apache Tomcat or Eclipse Jetty.

I have read about Quartz as one of the popular job schedulers for web applications. Would it be better (maybe because of better servlet container integration) to port this application from ScheduledExecutorService to Quartz?

Adding another library dependency to the application is not a problem, I am interested in technical reasons against usage of ScheduledExecutorService.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野の 2024-10-19 07:45:51

这取决于您使用它的目的。

石英对于编程时间很有用,例如每小时整点。

ScheduledExecutorService 对于重复不必在特定时间发生的任务非常有用。它更简单并且可能更有效。如果你有这个工作,它向我表明你不需要石英。

It depends on what you are using it for.

Quartz is useful for programmed times e.g. every hour on the hour.

ScheduledExecutorService is useful for repeating tasks which don't have to occur at a specific time. Its simpler and possibly more efficient. If you have this working it indicates to me that you don't need Quartz.

一杯敬自由 2024-10-19 07:45:51

ScheduledExecutorService 在较低级别运行,您必须自己实现所有调度监控/维护设施。

Quartz 拥有大量设施,例如作业持久化、事务、集群等。

ScheduledExecutorService operates at a lower level and you'd have to implement all scheduling monitoring/maintenance facilities yourself.

Quartz has tons of facilities such as Job Persistence, Transactions, Clustering etc.

苄①跕圉湢 2024-10-19 07:45:51

Java 的 Executor 解决方案允许您执行以下任一操作:

  1. 立即运行任务
  2. 在初始延迟后启动任务(并且可以选择在后续延迟周期后重新运行任务)。

但 Quartz 为您提供了运行任务/作业的时间和频率的令人难以置信的灵活性。例如,周一至周五工作周有一个时间表,周末有其他时间表(或根本没有时间表)。或者在该月的最后一天,您不必弄清楚给定月份的最后一天是 28 日、29 日、30 日还是 31 日。以下是 cron 风格调度所提供的灵活性的更多示例 - http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html#examples

使用 Java 库更容易,但对于任何想要快速入门的人来说-Quartz 工作的bones 代码库示例,我已将此模板放在一起以供免费下载使用 - https:// github.com/javateer/quartz-example

Java's Executor solution allows you to either:

  1. immediately run a task
  2. start a task after an initial delay (and optionally rerun the task after subsequent delay cycles).

But Quartz empowers you with incredible flexibility on when and how often to run a task/job. For example, one schedule during the Mon-Fri work week and something else (or not at all) during the weekends. Or on the last day of the month and you don't have to figure out if a given month's last day is on the 28th, 29th, 30th, or 31st. Here's some more examples of the flexibility the cron style scheduling accommodates - http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html#examples

Using Java's library is easier but for anyone that wants a jump start into a bare-bones codebase example of Quartz working, I've put this template together for free download usage - https://github.com/javateer/quartz-example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文