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 .
-
This question is not duplicate to the linked post and no solution found for such problem.– NHSCommented Jan 18, 2022 at 16:28
Add a comment
|
1 Answer
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.