Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB3 + JEE6: What is a persistent Timer?

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 :)

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

JavaDoc TimerConfig says: The persistent property determines whether the corresponding timer has a lifetime that spans the JVM in which it was created. It is optional and defaults to true.

like image 462
Hank Avatar asked Apr 20 '10 07:04

Hank


People also ask

What is a persistent timer?

Persistent Timer – To deal with a zero-window-size deadlock situation, TCP uses a persistence timer. When the sending TCP receives an acknowledgment with a window size of zero, it starts a persistence timer. When the persistence timer goes off, the sending TCP sends a special segment called a probe.

Which of the following are valid ways to create non persistent timers?

Nonpersistent programmatic timers are created by calling TimerConfig. setPersistent(false) and passing the TimerConfig object to one of the timer-creation methods.

What is the default period for the session object 10 minutes 1 20 minutes 2 30 minutes 3 40 minutes?

Specifies the number of minutes that a session can remain idle before the server terminates it automatically. The default is 10 minutes. Session.

How does EJB timer work?

Timer Service is a mechanism by which scheduled application can be build. For example, salary slip generation on the 1st of every month. EJB 3.0 specification has specified @Timeout annotation, which helps in programming the EJB service in a stateless or message driven bean.


1 Answers

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 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.

like image 162
Brett Kail Avatar answered Sep 23 '22 15:09

Brett Kail