EJB定时器使用建议
我想安排一个作业,读取一些实体,调用一些 ws 并写入/更新一些实体。此作业应在月亮之后处理,例如凌晨 1 点。关于这个问题我有两个问题。首先是 Scheduler 采用常量参数,我的要求是 Scheduler 应该可以通过一些 ui 进行调整。有没有合适的方法来做到这一点?否则,我必须调整调度程序,例如每 30 分钟调整一次,并且在方法内部,我必须查看一些可变时间值,无论它们是否满足。第二个问题是在 Scheduler 方法 usertransaction 内部启动,当我调用该方法(调用 utx.start)时,我得到“线程已经与事务关联!”实验值。我该怎么办?请推荐。提前致谢。
I want to schedule a job, which read some entities, call some ws and write/update some entities. This job should be processed after the moon, for example at 01am. I have 2 problems about this issue. First is that Scheduler takes constant parameters, my requeirement is that Scheduler should be adjustable via some ui. Is there a suitable way to do this? Otherwise I have to adjust the scheduler for example every 30 min, and inside the method I have to look some variable time values whether they are met or not. The second problem is inside the Scheduler method usertransaction is started, and when I call the method, which calls the utx.start, I get "thread is already associated with a transaction!" exp. What shall I do? Recommendation pls. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想创建变量计划表达式,那么您需要获取 TimerService(例如,@Resource Timerservice _timerService),然后使用 createCalendarTimer 方法,该方法将调用您的 @Timeout 方法。计时器的时间表是不可变的,因此 UI 在创建新计时器之前需要使用 getTimers() 来查找/取消现有计时器(可能通过匹配 getInfo())。
@Timeout 方法继承包含 bean 的事务功能。如果 bean 使用容器管理的事务,则 UserTransaction 将不起作用。
If you want to create variable schedule expressions, then you'll need to obtain TimerService (e.g., @Resource Timerservice _timerService), and then use the createCalendarTimer method, which will invoke your @Timeout method. A timer's schedule is immutable, so the UI will need to use getTimers() to find/cancel the existing timer (perhaps by matching getInfo()) before creating a new one.
@Timeout methods inherit the transaction capabilities of the containing bean. If the bean is using container-managed transactions, then UserTransaction will not work.
您可以公开托管 Bean 来通过 JMX 控制台管理此计时器。
对于第二个问题,您似乎将事务配置为由容器管理。然后,当该方法启动时,事务将自动启动。您可以禁用此自动管理,或者更好的是,避免编程管理并让容器管理事务。
You could expose a Managed Bean to manage this timer through JMX console.
For your second problem, it seems that you configured the transactions to be managed by the container. Then, when the method launches, a transaction is automatically started. You can disable this automatic management, or yet better, avoid programmatic management and let the container manage transactions.