Skip to content

Allow tasklets to run without transaction synchronization - #5479

Open
n-dlms wants to merge 1 commit into
spring-projects:mainfrom
n-dlms:GH-4912
Open

Allow tasklets to run without transaction synchronization#5479
n-dlms wants to merge 1 commit into
spring-projects:mainfrom
n-dlms:GH-4912

Conversation

@n-dlms

@n-dlms n-dlms commented Aug 4, 2026

Copy link
Copy Markdown

Resolves gh-4912

Summary

TaskletStep$ChunkTransactionCallback.doInTransaction called
TransactionSynchronizationManager.registerSynchronization(this)
unconditionally. When the configured transaction manager does not
activate transaction synchronization (e.g. SYNCHRONIZATION_NEVER, or
SYNCHRONIZATION_ON_ACTUAL_TRANSACTION without an actual
transaction), this throws IllegalStateException: Transaction synchronization is not active and fails the step.

This PR:

  • Registers the chunk transaction synchronization only when
    TransactionSynchronizationManager.isSynchronizationActive().
  • Releases the step execution lock after the transaction completes
    when the afterCompletion callback can never fire. Without this, a
    repeating tasklet would hang on the next chunk because the lock is
    only released in afterCompletion.

Tests

  • testTaskletRunsWithoutTransactionSynchronization: a tasklet step
    completes with a transaction manager configured with
    SYNCHRONIZATION_NEVER.
  • testTaskletRepeatsWithoutTransactionSynchronization: a
    CONTINUABLE tasklet runs to completion in the same configuration
    (guards against the lock-release hang).

Register the chunk transaction synchronization callback only when
transaction synchronization is active. When a transaction manager is
configured with SYNCHRONIZATION_NEVER or
SYNCHRONIZATION_ON_ACTUAL_TRANSACTION without an actual transaction,
registerSynchronization used to throw an IllegalStateException which
failed the step.

In that case the afterCompletion callback is never invoked, so the
step execution lock must be released after the transaction completes,
otherwise repeating tasklets would hang.

Closes spring-projectsgh-4912

Signed-off-by: Ntokozo Dlamini <ntokozo.dlamini.xyz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SYNCHRONIZATION_ON_ACTUAL_TRANSACTION not supported which leads to L1 cache problems in JPA

1 participant