This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Can I be notified before a transaction is committed?  RSS feed

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!