/** * Activate transaction synchronization for the current thread. * Called by a transaction manager on transaction begin. * @throws IllegalStateException if synchronization is already active */ publicstaticvoidinitSynchronization()throws IllegalStateException { if (isSynchronizationActive()) { thrownew IllegalStateException("Cannot activate transaction synchronization - already active"); } logger.trace("Initializing transaction synchronization"); synchronizations.set(new LinkedHashSet<>()); }
/** * Register a new transaction synchronization for the current thread. * Typically called by resource management code. *
Note that synchronizations can implement the * {@link org.springframework.core.Ordered} interface. * They will be executed in an order according to their order value (if any). * @param synchronization the synchronization object to register * @throws IllegalStateException if transaction synchronization is not active * @see org.springframework.core.Ordered */
Assert.notNull(synchronization, "TransactionSynchronization must not be null"); if (!isSynchronizationActive()) { thrownew IllegalStateException("Transaction synchronization is not active"); } synchronizations.get().add(synchronization); }