Reputation: 199
I will explain my problem little bit in details. – i have following classes
Consider the following scenario.
Request 1: jms message to save a student.
Request 2(this request will come with in some milliseconds): jms message to get the student.
There is a some time gap(may be some milliseconds) between these two threads. but here i am able to see changes in db. but they are not visible to thread2.
Can some throw light on this problem.
Thanks, Ramki.
Upvotes: 0
Views: 781
Reputation: 691685
This is exactly these kinds of problems that 2 phase commit resolves. The write to the JMS queue and the save in the database should be part of the same global 2PC transaction, so that both are done, or none are done. This would guarantee that the second thread only received the JMS message if and only if the user has been saved in the database.
Java EE appservers provide XA-enabled (2 phase commit) transaction managers. If you're not running inside a Java EE appserver, you might sill integrate one yourself in the application, like Bitronix, Atomikos, or other stand-alone transaction managers.
Upvotes: 1
Reputation: 70564
Sounds like you are using different resources (DB, JMS) to implement a business transaction, but don't synchronize the resource transactions, i.e. the JMS and DB transaction commit at different times, resulting in an inconsistent system state.
This is a standard architectural problem. Standard solutions include:
Upvotes: 0
Reputation: 41
Are this threads running on different JVM?
We've had similar problems when one process on a JVM commits a transaction to the database, and other process on another JVM not seeing the change because it is reading the value from it first or second level cache.
Upvotes: 0