aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Difference between Single phase and two phase commit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Difference between Single phase and two phase commit" Watch "Difference between Single phase and two phase commit" New topic
Author

Difference between Single phase and two phase commit

Raj Jindal
Ranch Hand

Joined: Jan 17, 2003
Posts: 50
Can anybody plz explain me the difference between a single phase and two phase commit. which type of commit does JDBC uses.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The two-phase commit (also known as "2PC") means that the transaction manager first sends out a "prepare for commit" message to all participants and starts waiting for acknowledgement messages. Once the owner has received "OK" from every participant, it sends out a "commit" message. If it didn't receive an OK from some participant, it sends out a "rollback" message to all participants. When talking about a single phase commit, the transaction manager only sends out one message, "commit".
The reason why 2PC is needed is distributed transactions. For example, you might have two separate databases being modified within a single transaction. If we have committed the first modification but the second fails, there's no way to rollback the first one anymore.
For a better and more thorough/accurate explanation for 2PC, consult Google.
As to your question about which of these is JDBC using, it uses both. At least in theory. If you have an XA-capable JDBC driver, it should be able to implement the 2PC protocol as well as the normal single-phase commit protocol.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Single phase and two phase commit