EJB3 + JEE6:什么是持久性计时器? [英] EJB3 + JEE6: What is a persistent Timer?

查看:77
本文介绍了EJB3 + JEE6:什么是持久性计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要使用新的EJB3 TimerService(作为Java EE 6的一部分),并且像往常一样,我对JavaDoc的简洁性印象深刻:)

I'm just about to use the new EJB3 TimerService (as part of Java EE 6), and as usual, I'm impressed by the brevity of JavaDoc :)

您知道 TimerConfig 对象的 persistent 属性的作用是什么吗?

Do you know what is the effect of the persistent property of the TimerConfig object?

JavaDoc TimerConfig 说: persistent属性确定相应的计时器是否具有跨越创建该计时器的JVM的生存期。它是可选的,默认为true。

推荐答案

persistent属性表示需要容器来保留计时器状态到数据库。如果您需要确保即使服务器脱机(故意或崩溃),计时器也将触发,则这一点很重要。服务器重新联机后,需要执行错过的计时器。将计时器设置为永久计时器还具有确保计时器仅在一个服务器JVM中执行(但不一定在创建它的计时器中执行)的副作用,无论这对您的产品意味着什么。例如,在集群服务器环境中,这通常意味着即使EJB模块在3个JVM上运行,也只有一个JVM将执行计时器。

The persistent property means that the container is required to persist the timer state to a database. This is important if you need to guarantee that the timer will fire even if the server is taken offline (intentionally or crash). When the server comes back online, it is required to execute missed timers. Setting a timer as persistent also has the side-effect of ensuring that the timer only executes in one server JVM (but not necessarily the one that created it), whatever that means for your product. For example, in a clustered server environment, this typically means that even if EJB module is running on 3 JVMs, exactly one JVM will execute the timer.

persistent = true是EJB 3.1之前唯一可用的选项。某些计时器操作不够关键,无法保证达到此级别的可靠性,因此添加了该选项以允许使用非持久计时器。将计时器设置为非永久计时器还具有确保其在创建计时器的JVM中运行的副作用。这对于更新内存缓存或静态HTML很有用。

persistent=true was the only option available prior to EJB 3.1. Some timer operations are not critical enough to warrant this level of reliability, so the option was added to allow non-persistent timers. Setting a timer as non-persistent also has the side-effect of ensuring it runs in the JVM in which it was created. This can be useful for updating an in-memory cache or static HTML.

这篇关于EJB3 + JEE6:什么是持久性计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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