Adam Bien's Weblog

Tuesday Jul 30, 2013

EJB 3.2--Listing All Timers

The useful method:


public Collection getTimers() throws IllegalStateException, EJBException

from the class javax.ejb.TimerService returns all javax.ejb.Timer instances from the module. The EJB 3.2 specification (Java EE 7) defines the functionality as:
The getAllTimers method returns active timers associated with the beans in the same module in which the caller bean is packaged. These include all active persistent timers regardless of the number of JVMs across which the container is distributed, and active non-persistent timers created in the same JVM as the executing method. Timers returned by this method include both the programmatically-cre- ated timers and the automatically-created timers.
Page 341, Enterprise JavaBeans 3.2 Specification (http://www.jcp.org/en/jsr/detail?id=345)

Now we can easily build a timer management solution, with nothing but vanilla EJB 3.2. KISS -> Java EE 7 :-)

See you at Java EE Workshops at MUC Airport!


Special Event: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014

A book about rethinking Java EE Patterns

Comments:

Hello Adam, thanks, yes it's very useful method.
I always use this method for example when i need to find timers by some criteria and do something with them (cancel for example).
But getTimers was already defined in EJB 3.1 specification in javax.ejb.TimerService interface

From EJB 3.1 specification:
The getTimers method returns the active timers associated with the bean. For an EJB 2.1 entity bean, the result of getTimers is a collection of those timers that are associated with the bean’s identity.

Posted by Vitaliy Kalayda on July 30, 2013 at 11:38 PM CEST #

@Vitaliy

He meant getAllTimers() which is new and differs from getTimers() in that the returned list is all timers across all beans in the module.

Doing that before would have been impossible as listing all beans in a module is not really possible.

Posted by David Blevins on November 12, 2013 at 09:18 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
Links
License