Commit and Rollback Events
Java’s try-catch-finally facility allows us to handle exceptions and selectively run some code only when there’s an exception. Similarly, we can decide to run a piece of code only if a transaction committed and another piece of code only if a transaction rolled back. These are provided as deferred and compensating methods, respectively, on StmUtils. The deferred method is a great place to perform all the side effects that we were holding off to ensure the transaction completes.
Commit and Rollback Events in Java
We place the code that we want to run when a transaction succeeds in the code block (Runnable) that’s passed to the deferred method of StmUtils. Likewise, we’ll place the code we want to run when the transaction ...