• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

What is 2 phase-commit ?

Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain 2 phase-commit ??

Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"2 phase commit" is a protocol for global transactions. A global transaction is one which happens over more than one distinct transactional resource. The "2 phase" part refers to the two distinct parts of the process, which work (roughly!) like this:
  • First, a coordination process starts and sends a prepare message to all the participants (the distinct transactional resources) - this message will include some sort of unique identifier. When they get the message, each of the resources do what they need to do to see if they can commit the transaction. If they can the respond with a vote commit message, or a vote abort message if they can't.
  • Second, the coordinator examines all the votes - if all the resources agree they can commit their specific transactions then a global commit message is send out, again with the unique ID. The resources now commit all their transactions.

  • In a J2EE app. you might use this sort of sequence of events to encapsulate a method which does a JDBC operation and some JMS stuff. Both the JDBC operation can fail and a JMS message can fail to be sent. If either fail inside an XA transaction (another common name for 2 phase commit) then the JDBC operation will be rolled back, and the JMS message will be removed.

    Hope that makes sense. (And I got it right!)
    Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
    Free, earth friendly heat - from the CodeRanch trailboss
      Bookmark Topic Watch Topic
    • New Topic