What does it mean to suspend a transaction?

If a transaction is in progress when a method on a BMT bean is called, the transaction is suspended. Temporarily. The transaction just sits there waiting for the BMT bean to complete its work. Work that’s not part of the caller’s original transaction. Once the BMT method finishes and is popped off the stack, the original transaction kicks back in, right where it left off.

Imagine this scenario: a CMT bean, bean one, is running a method foo() in a transaction (tx A) when it calls a method bar() on bean two (a BMT bean). Once bar() completes and pops off the stack, method foo() invokes another method, bee(), but this time the called bean is another CMT bean (bean three).

When a transaction is suspended, it waits until it can pick up where it left off. But this means that the things that happen while the transaction is suspended are NOT part of the same atomic unit. In other words, the things that happen while the transaction is suspended won’t be rolled back if the suspended transaction (after it comes back to life) fails to commit.

image with no caption
  1. Method foo() of a CMT bean is running in transaction A. Method foo() then invokes method bar() on a BMT bean.

    image with no caption
  2. Method bar() suspends transaction A, and starts a new transaction, B. Method bar() runs in the new transaction ...

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.