如何使EJB Timer Persistent为false [英] How to make EJB Timer Persistent to false

查看:169
本文介绍了如何使EJB Timer Persistent为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用的是EJB 3.0 Timers

I am using EJB 3.0 Timers in my application.

关于EJB计时器的一件事是它们默认是持久的,这意味着一旦服务器重新启动,计时器将自动被调用而无需再次调用它们。

One thing about EJB Timers is that they are by default persistent which means that when ever there is server restart the Timers will automatically be invoked with out calling them again.

我有一个要求,当服务器重新启动时,应该手动启动这些计时器。为此,我知道我们需要在配置XML中更改一些我不知道确切的属性。

I have a requirement that these timers should be manually be started when ever server is restarted. For this I know we need to change some attribute in config XML which I don't know exact.

我需要在哪里更改属性以设置 persistent = false

Where do I need to change the attribute to set persistent=false.

我正在使用Weblogic Server。

推荐答案

该线程很旧,但我认为现在这种担忧仍然存在。
自EJB 3.1起就有一个属性可以指定EJB持久性,如 @ mikko-maunu 所示。我认为它的建模有两个职责:

This thread is old, but I think the concerns still apply nowadays. There is an attribute since EJB 3.1 to specify EJB persistency, as @mikko-maunu indicated, yet I've perceived it was modeled with two responsibilities:


  • 在系统重新初始化后使计划配置继续存在;

  • 在系统初始化时重新触发所有最终触发失败的触发器。

我认为以上概念应该独立建模,因此我们可以将EJB计时器存储在数据库中,并且还可以更好地控制在系统重新初始化时对触发错误的触发器的处理方式,即应重新触发或忽略它们。

I think the concepts above should have been modeled independently, so we could have a EJB timer stored on a database, and also have finer control over what to do with misfired triggers at system reinitialization, i.e. should them be retriggered or ignored.

否则,基于EJB Timer的作业模块似乎有些尴尬,其中某些模块存储在数据库中,而另一些则不存储,只是因为我们不想为每小时安排的过于频繁的作业重新触发以前错过的触发器例如。

Otherwise, it would seem awkward having a EJB Timer based job module where some of them are stored in a DB and others are not, just because we don't want to refire previous missed triggers for a job scheduled too frequently, running at an hourly basis, for example.

I'v e注意到,在JBoss 7.1 / Java EE 7中,将日程表信息保存在数据库中可以潜在地支持对集群配置的中央控制,而不是具有非持久性日程表的重复和独立实例。但是,对于每天多次触发的作业,附带的影响是,在系统重新初始化时,所有最终触发失败的触发器都会立即触发。

I've noticed, in JBoss 7.1 / Java EE 7, that keeping the schedule information in a database can potentially support a central control for a clustered configuration, instead of having repeated and independent instances of non-persistent time schedules. But the colateral effect is having, for a job triggered many times a day, all eventially misfired triggers fired at once at system reinitialization.

要在重新启动时更好地控制持久EJB计时器,我们可以在 @PostConstruct 方法中检查计时器的 getNextTimeout()是过去的时间。如果计时器应该忽略触发错误的触发器,则可以使用相同的scheduleExpression取消旧计时器并立即创建一个新计时器,因此仅考虑将来的触发器。对于计划每天运行多次的计时器来说,这似乎很有用。

To have finer control over a persistent EJB Timer at restart time, we could, at the @PostConstruct method, check if the timer's getNextTimeout() is a past time. If the timer should ignore misfired triggers, we could cancel the old timer and immediately create a new one, using the same scheduleExpression, so only future triggers will be considered. This seems very useful for timers scheduled to run many times a day.

另一种可能,也许更简单的方法是 @Timeout 方法,检查计时器的下一个执行时间 getNextTimeout()是否在当前日期和时间之前,然后确定以前的时间,错误触发的触发器应予以处理或丢弃。

Another possible, maybe simpler approach is, in the @Timeout method, check if the timer's next execution time, getNextTimeout(), is before the current date and time, and then decide if previous, misfired triggers should be treated or discarded.

这篇关于如何使EJB Timer Persistent为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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