i have few questions on Ejb3 timers, kindly clarify
a)supoose the timer is created for 5min and during that transaction rolled back @ 3rd min(rollback attribute is true), what will happen to timer, will it be recreated on its own? if so what will be the timer expiration, 5min or 2min
b)supoose the timer is created for 5min and suddenly the server crashed @ 3rd min, when server comes up again, what will happen to timer, will it be recreated on own?if so what will be the timer expiration, 5min or 2min
What about nested Timers, some where in the inner loops, runtime exception is thrown, what will be the behaviour
I am new to EJB and was reading about Timers for the first time last night.
"Mastering EJBs" says
TIMERS AND TRANSACTIONS
The creation of timers is supported within transactions.
Therefore, if an enterprise bean method that creates the timer is executed as
part of a transaction and if that transaction is rolled back, the timer creation is
rolled back too. Similarly, if an enterprise bean method cancels the timer by
calling cancel() on the Timer interface within a transaction and if that
transaction is rolled back, the container rolls back the timer cancellation as
well. The container restores the duration of the timer to the duration it would
have had, had it not been rolled back.
The timeout callback method can also be called within a transaction and
typically has transaction attributes of REQUIRES or REQUIRES_NEW. Hence, if
the transaction rolls back, the container will call the timeout callback method
which I think answers your first question.
EJB in Action says
However, unlike stateless session beans and MDBs, timers are persistent and can survive a container crash or restart.
which I think answers your second question.
I am unclear however whether you have to explicitly persist the Timer handle or whether the Container is just resiliant in this respect.
A quick test by writing a Timer would prove whether it worked for your Container - have you tried this?
whenever the timer is created under any transaction, and that transaction rolls back due to the reasons stated by you, the timer creation will also be rolled back.
But if the timer is already created, and the time is elapsing then at the point of time, when the server crash, upon restart the container must try at least once to call the same timeout callback method with the same time elapse, when it was crashed.