Skip to content

Document that @Transactional does not propagate to new threads #25439

@kanjih

Description

@kanjih

When you make a new thread in the method enclosed by @Transactional, transaction does not propagate to the new thread.

For example, in the below case, write1 will rollback but write2 won't.

@Transactional
public void methodA() {
  write1();
  CompletableFuture.runAsync(() -> write2(), Executors.newSingleThreadExecutor());
  if (true) {
    throw new RuntimeException();
  }
}

We need to make clear whether this is the specification or the bug.

Reference: Spring Transaction Management Over Multiple Threads

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: documentationA documentation task

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions