I have a method as below:
ClassA.java
@Transactional
public void methodA(){
ExecutorService executorService = Executors.newFixedThreadPool(4);
executorService.execute(new Runnable() {
public void run() {
classB.methodB();
}
});
}
ClassB.java
@Transactional
public void methodB(){
updateDB();
}
Can the methodB work well? Per my understanding, methodB will attach the transaction of methodA, what if methodA exits before methodB? I guess only methodA can be commited by the transaction. But methodB will not commit because the transaction commited before.
Can I use @Transactional(propagation = Propagation.REQUIRES_NEW) for methodB. This can let methodB have a new transaction. But according to spring doc, the transcation of methodA will suspend when it invoke methodB. I feel very confuse here.
Can anyone help me on this issue? Thanks in advance.