• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Single phase and two phase commit

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic