This is one of the most popular JDBC Interview questions and asked at an advanced level, mostly to senior Java developers on J2EE interviews. Two-phase commit is used in a distributed environment where multiple processes take part in the distributed transaction process. In simple word we can understand like if any transaction is executing and it will affect multiple databases then a 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 .
Posted Date:- 2021-09-03 21:50:51