Transactions
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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access