• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Transaction and 2 PC

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could any one explain me the difference between transaction and a 2 phase transaction ?

Thanks in advance,

Srinu
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A transaction ensures "atomicity" of a unit of work. That means either it all succeeds or everything is reset to the point it was before the unit started. A bank transfer is a good example. To transfer money from account A to account B, you subtract money from account A and add the same amount to account B. This work may fail at any point. Assume it fails after the balance of A is reduced, but before the balance of B is increased. The money disappears! In this case, we must somehow reset the balance of A to what it was before the transfer, i.e., before the start of the transaction.

Fortunately, databases let us make temporary changes, then either commit them to make them permanent, or roll them back to erase them. However, when one transaction uses multiple databases (or other resources), we need a resource manager, like what an application server provides. This manager supports two-phase commit (not two-phase transactions). In phase one, the manager asks each resource if it's OK to commit the changes. If every single one of them says it's OK, then phase two is the manager issuing the commit command to all resources. If any resource says it can't commit, then the manager commands all resources to rollback.

It's actually a fairly simple concept, but tricky to implement. That's why we're lucky the app server vendors have already done it for us!
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg, Whether 2-phase commit(resource manager) is one of the J2EE application server/container provided services ? Can you give the example for 2-phase commit like Transaction ?
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic