posted 11 years ago
Hi!
Is there any way (preferrably with container-managed persistence, but even manually) to implement 2 transactions in EJB3 that fullfil the following criteria:
a)
pseudo-code:
T1 {
doSomething1
start T2 in background
doSomething2
commit
}
T2 {
doSomething
commit
}
b)
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
c)
graphically:
("_" = "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.
Any ideas?
Thanks,
Agoston