Skip to main content
Advertisement

11.3 In-Depth Transaction Propagation and Isolation Levels

Advancing beyond solitary isolated transactions, when sequentially invoking neighboring @Transactional methods or aggressively accommodating thousands of concurrent macroscopic active DB mutations, meticulously orchestrating Propagation thresholds and Isolation constraints is an absolute production prerequisite.

1. Transaction Propagation Behavior

When an active transactional block subsequently triggers an independent @Transactional declared routine elsewhere, this directive mechanically dictates whether to passively homogenize (Join) the pre-existing infrastructure or brutally spawn an entirely isolated child connection pipeline.

  • REQUIRED (System Default): Passively assimilates into pre-existing Parent transactions contextually if detected, inherently fabricating a fresh envelope otherwise. Consequently, if ANY linked segment suffers Rollback, the entire integrated network reverts concurrently.
  • REQUIRES_NEW: Unequivocally abandons inheriting parent contexts, forcefully orchestrating its own structurally detached, autonomous physical database connection. Crucially, if this Child node violently crashes (Rollback), mathematically wrapping the propagating Exception locally within a try-catch allows the resilient Parent connection to stubbornly hit Commit flawlessly untouched. (Ideal architectural design for vital systemic Logging streams).
  • SUPPORTS: Assimilates cleanly if a parent is aggressively discovered, but smoothly degrades to Non-transactional raw bypass logic if initiated plainly absent of structural boundaries.
  • MANDATORY: Demands a functional parent Transaction presence with extreme prejudice, instantly triggering vicious runtime Exceptions immediately otherwise.
@Service
public class OrderService {
@Transactional(propagation = Propagation.REQUIRED)
public void createOrder() {
// ...
logService.saveLog(); // Forcefully segregated mathematically utilizing REQUIRES_NEW
}
}

2. Transaction Isolation Levels

When heavily collided parallel threads aggressively compete attempting malicious simultaneous edits over singular DB domains, this rigorously specifies the degree of data concealment (Locking) mandated natively. Escalating the isolation threshold dramatically stabilizes Absolute Integrity while fatally strangling overall Concurrent throughputs (severe Lock contention decay).

  1. READ_UNCOMMITTED: Aggressively peeks at phantom modifications rendered arbitrarily by neighboring threads before explicit Commits finalize. (Introduces notorious Dirty Reads; absolutely criminal in Enterprise systems).
  2. READ_COMMITTED (Oracle, PostgreSQL Default): Safely restricts visibility strictly exposing solely firmly committed variants. The implicit detriment involves Non-Repeatable Reads natively—two identical internal queries executed linearly returning disparate metrics due to arbitrary mid-flight external commits.
  3. REPEATABLE_READ (MySQL Default): Formidably freezes perspective natively anchoring onto the fixed snapshot timestamp generated at initial invocation. Fundamentally guarantees identical deterministic query read outputs regardless of external thread interference tampering.
  4. SERIALIZABLE: Supremely restrictive absolute barricade. Forces all parallel transactions aggressively into a literal strictly single-threaded chronological queue. Given astronomical performance degradations, it is functionally ostracized except strictly operating specialized high-finance core ledger mutations cautiously.
@Transactional(isolation = Isolation.REPEATABLE_READ)
public void updateInventory() {
// Intensive deterministic inventory subtraction algorithms
}
Advertisement