EJB 3中TimerService的Spring替代品 [英] Spring alternative to TimerService in EJB 3

查看:101
本文介绍了EJB 3中TimerService的Spring替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

它工作正常,但是我觉得我们已经接近您应该如何使用EJB的边界了.

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

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

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

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

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.

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

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?

工作类型

ProcessEngine

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

StatisticsCollector

  • 默认情况下应每天晚上3点运行
  • 应该能够立即按需运行

推荐答案

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

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

它是开源的,可扩展的并且功能强大.通过CRON表达式来安排时间,可以满足您帖子中指定的需求

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

与EJB相比,Quarts的缺点是:开箱即用,计划的作业不是持久性的,它创建了自己的线程池(无法在运行时调整大小),并且它的线程算法不公平.(即,如果一项工作由于饥饿而在指定的时间没有被解雇,它将被报废).尽管如此,我在整个Quartz方面还是有很好的经验.

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.

这篇关于EJB 3中TimerService的Spring替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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