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
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.
We need to make clear whether this is the specification or the bug.
Reference: Spring Transaction Management Over Multiple Threads