Please send your Questions & Answers or Feedback to "mohan@javabook.org"

What is 2 phase commit?

This is one of the most popular JDBC Interview question and asked at advanced level, mostly to senior Java developers on J2EE interviews. Two phase commit is used in distributed environment where multiple process take part in distributed transaction process. In simple word we can understand like if any transaction is executing and it will effect multiple database then two phase commit will be used to make all database synchronized with each other.

 

In two phase commit, commit or rollback is done by two phases:

1.Commit request phase: in this phase main process or coordinator process take vote of all other process that they are complete their process successfully and ready to commit if all the votes are “yes” then they go ahead for next phase. And if “No “then rollback is performed.

2.Commit phase: according to vote if all the votes are yes then commit is done.

 

Similarly when any transaction changes multiple database after execution of transaction it will issue pre commit  command on each database and all database send acknowledgement and according to acknowledgement if all are positive transaction will issue the commit command otherwise rollback is done .

Related Posts Plugin for WordPress, Blogger...
Flag Counter