Is there any way (preferrably with container-managed persistence, but even manually) to implement 2 transactions in EJB3 that fullfil the following criteria:
start T2 in background
conditions: T2 "depends" on T1 in the sense that
1. T2 starts during T1
2. if T1 is rolled back ==> T2 must be rolled back, too
(==> this implies: T2 ends after T1 OR T2 waits for T1 to finish before committing)
3. if T2 is rolled back ==> doesn't cause T1 to rollback
("_" = "commit", "." = waiting)
The hardest part seems to me to make T2 wait until T1 finishes (in the otherwise unlikely but possible case that T1 finishes first). You can safely presume that the two transactions run on the same JVM, but of course a solution that doesn't rely on this presumption would be even better.
I have tried to find ways for T2 to somehow monitor T1, but on my first half-hearted try I couldn't find anything.
Joined: Nov 23, 2007
Can't you Coderanch guys get rid of this Javarebel spam? I see it in messages all the time here.
you can solve this problem with the asynchrous message (JMS). You are sending the message from the middle of code but in fact the container will send it after T1's commit (T1 is transactional). So if T1 is rollbacked then the message will not be sent. If there is no rollback message will be sent and consumed by T2. Rollback of T2 doesn't affect T1.
subject: Second transaction in the background in an EJB3 application?