EJB3 + JEE6: What is a persistent Timer?
Asked Answered
S

1

39

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.

Supernova answered 20/4, 2010 at 7:47 Comment(0)
M
60

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.

Maimaia answered 23/4, 2010 at 5:42 Comment(4)
so generally a good idea to have it true. which is the defaultRecreant
"to persist the timer state to a database" - can you explain to which database the timer is saved? Will timer be saved if I don`t use any db?Husch
@AntonSorokin The answer is vendor-specific. I suggest creating a new question about your specific vendor.Maimaia
@AntonSorokin the container genrally has something like a DerbyDB or similar standalone running there for thatTrull

© 2022 - 2024 — McMap. All rights reserved.