• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Second transaction in the background in an EJB3 application?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Agoston Bejo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you Coderanch guys get rid of this Javarebel spam? I see it in messages all the time here.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic