When a bean
calls createTimer( )
, the operation is performed
in the scope of the current transaction. If the transaction rolls
back, the timer is undone: it’s not created (or,
more precisely, uncreated). For example, if the Ship
EJB’s scheduleMaintenance( )
method has a transaction attribute of RequiresNew
,
a new transaction will be created when the method is called. If an
exception is thrown by the method, the transaction rolls back and the
new timer event is not created.
In most cases, the ejbTimeout( )
method on beans
should have a transaction attribute of
RequiresNew
. This ensures that the work performed
by the ejbTimeout( )
method is in the scope of
container-initiated transactions. Transactions are covered in more
detail in Chapter 16.