-
1. Re: Number of @Schedule method execution re-runs on exception
rhanus May 6, 2013 4:57 AM (in response to draken123)EJB 3.1 spec: 18.4.3 Timer Expiration and Timeout Callback Method
"If container-managed transaction demarcation is used and the REQUIRED or REQUIRES_NEW transaction attribute is specified or defaulted (Required or RequiresNew if the deployment descriptor is used), the container must begin a new transaction prior to invoking the timeout callback method. If the transaction fails or is rolled back, the container must retry the timeout at least once."
you shouldn't be able to refuse the retry by setting a configuration option
on the other hand catching exception a setting rollback only doesn't help because:
"If the Bean Provider invokes the setRollbackOnly method from within the timeout callback method, the container must rollback the transaction in which the timeout callback method is invoked. This has the effect of rescinding the timer expiration. The container must retry the timeout after the transaction rollback."
simply catch runtime exceptions and provide some recovery if possible and return from timeout callback method
-
2. Re: Number of @Schedule method execution re-runs on exception
draken123 May 6, 2013 3:49 PM (in response to rhanus)Dear Radim,
thanks for a detailed explanation. Now I at least know why the method was re-run on exception.
Radim Hanus wrote:
(...)
simply catch runtime exceptions and provide some recovery if possible and return from timeout callback method
I was doing the above in my code - I was catching all exceptions (runtime and checked alike) and then I was sending an email (from the catch block) to my own address, so I knew that something went wrong. The only problem was, that if something was wrong, I was getting the email twice, due to the original transaction being rolled back and the container retrying the timeout.
Best Regards,
Marcin