File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Single phase and two phase commit

 
Raj Jindal
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic