1.

What is Two phase commit in JDBC?

Answer»
  • Two-phase commit is useful for a distributed environment where numerous processes take part in the distributed transaction process. In simpler words, we can say that, if a transaction is executing and it is affecting multiple databases then a two-phase commit will be used to make sure that all databases are synchronized with each other.
  • In two-phase commit, commit or ROLLBACK is performed by two phases given below:
    • Commit request phase: In this phase, the main process or co-ordinator process take a vote of all other process that they have COMPLETED their process successfully and ready to commit, if all the votes are “yes” then they CONTINUE for the NEXT phase. And if “No” then rollback will be performed.
    • Commit phase: As per vote, if all the votes are “yes” then commit is DONE.
  • In the same way, when any transaction changes multiple databases after transaction execution, it will issue a pre-commit command on each database and all databases will send an acknowledgment. Based on acknowledgment, if all are positive transactions then it will issue the commit command otherwise rollback will be done.


Discussion

No Comment Found