How to use spring transaction in multithread

后端 未结 1 1350
旧巷少年郎
旧巷少年郎 2020-11-30 03:14

I have a method as below:

ClassA.java
@Transactional
public void methodA(){        
    ExecutorService executorService = Executors.newFixedThreadPool(4);
           


        
相关标签:
1条回答
  • 2020-11-30 03:38

    No, methodB() will not be executed in the same transaction as methodA(). Spring's @Transactional only works on a single thread - it creates a session when a thread first enteres a method with @Transactional (or a method in a class with @Transactional), and then commits it when it leaves that method.

    In your example, the transaction will end after you schedule the job in the thread pool. methodB() will have it's own transaction.

    0 讨论(0)
提交回复
热议问题