EJB 3 中 TimerService 的 Spring 替代方案

发布于 2024-09-16 01:47:32 字数 1117 浏览 3 评论 0原文

我们使用 EJB TimerService:s 来控制需要按需执行或通过 cron 表达式触发的任务,有些任务每晚运行一次,例如统计收集器,有些任务每 10 秒运行一次,例如检查需要处理的新订单,我们还必须能够打开和关闭它们。大多数情况下它工作正常,但有时进程无法停止,解决问题的唯一方法是刷新 TimerPool 并重新部署应用程序。

我一直在寻找问题的另一种解决方案,并且我们尝试了一个具有更多控制功能的版本,如下例所示: http://www.adam-bien.com/roller/abien/entry/ legal_starting_threads_in_ejbs

它工作得很好,但我感觉我们已经非常接近您应该如何使用 EJB 的边界了。

我一直在寻找任务执行和调度: http://static.springsource。 org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

这似乎是摆脱 EJB:s 的一种方法,因为我们只将它们用于 TimerService 和控制器和实际任务之间的通信。

问题是我需要比静态配置文件更多的控制,也许自制的 SchedulerFactoryBean 可以工作,但我真的不知道应该从哪里开始寻找?

作业类型

ProcessEngine

  • 每 10 秒执行一次,检查是否有新客户并处理他们的订单
  • 应该能够使用肥皂或肥皂打开和关闭引擎通过数据库

StatisticsCollector

  • 中的设置默认情况下应该每晚凌晨 3 点运行
  • 应该能够根据需要触发立即运行

We're using EJB TimerService:s for controlling tasks that needs to be executed on demand or triggered via a cron expression some will run every night e.g. statistic collectors and some will run every 10s e.g. checking for new orders needed to be processed we must also be able to turn them on and off. It works fine most of the time but sometimes the the processes cannot be stopped and the only way to fix the problem is to flush the TimerPool and redeploy the application.

I have been looking for a another solution of our problem and we have tried a version, with more controlling functionality , of the example below:
http://www.adam-bien.com/roller/abien/entry/legally_starting_threads_in_ejbs

It works fine but I've got the feeling we're pretty close to the boundary of how you should work with EJBs.

I have been looking a Task Execution and Scheduling:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

And it seems like a way to get rid of the EJB:s since we're only using them for the TimerService and the communication between the controller and the actual task.

The problem is that I need more control than static configuration files and perhaps home brewed SchedulerFactoryBean would work but I don't really know where I should start looking?

Type of jobs

ProcessEngine

  • Will be executed every 10s and check if there are any new customers and process their orders
  • Should be able to turn the engine ON and OFF, either with soap or via a setting in the DB

StatisticsCollector

  • Should run every night at 3am by default
  • Should be able to be triggered to run right now on demand

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

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

发布评论

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

评论(1

┾廆蒐ゝ 2024-09-23 01:47:32

从上面的评论来看,我猜测您需要一个更复杂的调度程序。您是否考虑过使用Quartz Scheduler

它是开源的、可扩展的并且非常强大。调度是通过 CRON 表达式完成的,它可以满足您在帖子中指定的需求

Quarts 与 EJB 相比的缺点是开箱即用,调度的作业不是持久的,它创建自己的线程池(无法调整大小)在运行时),并且它的线程算法没有公平性(即,如果一个作业由于饥饿而没有在指定的时间触发,它就会被废弃)。尽管如此,我对 Quartz 整体还是有很好的体验的。

From the comment above, I'm guessing that you need a far more complex scheduler. Have you thought about using Quartz Scheduler?

It's open source, extendable and quite powerful. Scheduling is done via CRON expressions, which can fill the needs specified in your post

The disadvantages to Quarts in comparison to EJB is that out of the box, scheduled jobs are not persistent, it creates its own threading pool (which can't be resized at runtime), and there is no fairness to it's threading algorithm (i.e. if a job hasn't fired at its assigned time due to starvation, it gets scrapped). Still, I've had good experiences with Quartz as a whole.

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