1

There is a method in service which is annotated with @Transacational. In this method we perform some delete operations and after we want to spawn a new thread and delete some more entries. If there are any exception with the later one. DB is going to inconsistent state because few entries got deleted. Can I propagate transaction to Thread. I read some article on this but could not succeed .

1
  • This question is not duplicate to the linked post and no solution found for such problem.
    – NHS
    Commented Jan 18, 2022 at 16:28

1 Answer 1

0

Transaction status in spring is stored in a thread local manner. org.springframework.transaction.support.TransactionSynchronizationManager class. Thus transaction related thread local values set from the original delete thread cannot be accessed to the other spawned delete thread.

Also your threads have to be managed by spring in order for your @Transactional annotation to be effective. You need to spawn your threads from a spring ThreadPoolTaskExecutor.

Not the answer you're looking for? Browse other questions tagged or ask your own question.