Spring new transaction combined with Retryable

2020-04-16 06:57发布

问题:

If I have a method that has a Spring retryable for a certain exception, and also has a Transactional(Requires_new), every time the retry is done, will it create a new transaction or use the existing one?

ie

@Retryable(maxAttempts = 5, backoff = @Backoff(delay = 250), include = {ActivitiOptimisticLockingException.class})
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void setVariable(String processId, String variableName, String variableValue){
    engine.getRuntimeService().setVariable(processId, variableName, variableValue);
}

What will actually happen here?

回答1:

will be created new transaction each time. it the same as get service from spring context and call method N times. every call creates new transaction (use propagation that you added into service or method). Call your transactioanl servics method call it's call a proxy, retry calls that proxy also. Also your transaction might have timeout,retry try call in new timeout duration ,not N try times in one timeout