Entity Bean Timers
Entity
beans set
timers on a specific type of entity bean (e.g., Ship, Customer,
Reservation, etc.) with a specific primary key. When a timer goes
off, the container uses the primary key associated with the timer to
load the entity bean with proper data. Once the entity bean is in the
ready stateâits data is loaded and itâs ready
to service requestsâthe ejbTimeout( )
method
is invoked. The container associates the primary key with the timer
implicitly.
Using timers with entity beans allows entity beans to manage their own timed events. As weâve seen, it makes sense for a Ship to manage its own maintenance schedule. The maintenance schedule is unique for each ship and required in order to keep the ship sailing, so it could be considered intrinsic to the definition of a ship. If, however, the timed event is not a part of the entityâs definition, itâs best to put the timer into a taskflow bean (i.e., stateless session or message-driven) that represents the scenario, instead of placing the logic in the entity bean. This avoids entity bloat , in which an entity beanâs definition becomes huge from attempting to manage every possible application of the entity bean. Itâs the same reason we move taskflow logic out of entity beans and into session beans.
A serious concern with entity beans is the possibility of timer attack , which occurs when too many timers expire at the same time. A timer attack is not caused by malicious intent, but rather poor design. ...
Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.