• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can I be notified before a transaction is committed?

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a situation in which something needs to occur before a transaction is committed, but I cannot invoke this everywhere tx.commit() eventually gets called. Is there a way to configure a listener within JBoss such that it is notified before a transaction is committed (or at least before tx.commit() actually does the commit)?

Our application is using JBoss 4.0.1sp1.

Thanks,
Kelly
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the TransactionSynchronizationRegistry to register a Synchronization. The TransactionSynchronizationRegistry is portable and available in JNDI too.

See javadocs here:

http://docs.oracle.com/javaee/5/api/javax/transaction/TransactionSynchronizationRegistry.html#registerInterposedSynchronization%28javax.transaction.Synchronization%29
http://docs.oracle.com/javaee/5/api/javax/transaction/Synchronization.html
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

Specifically TransactionSynchronizationRegistry does not work in our case because it was introduced with JTA 1.1 and JBoss 4.0.1sp1 seems to only support JTA 1.0.1. However, JTA 1.0.1 supports the Synchronization interface and the Transaction interface defines a registerSynchronization() API.

I was able to create a class that implements Synchronization and registers it with the current transaction.


 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic