Distributed transactions: two-phase commit

Most EJB containers support distributed transactions through a two-phase commit protocol. If you’re a transaction manager (like a J2EE server), you might have multiple participants, including a database, another bean, and another server on the network. Once you’ve told everyone to commit, there’s no good way to undo it, so before you give the signal to commit, you need to make sure that everyone can do what you’re asking. As the transaction manager, your job is to find out if everyone is ready to perform (update the database, debit the account, etc.), and then, depending on the results, tell them all to do it (commit) or tell them all to forget it (rollback).

Off the path

image with no caption

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.