春季新交易与可重试结合 [英] Spring new transaction combined with Retryable

查看:106
本文介绍了春季新交易与可重试结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个方法可以针对某个异常重试Spring,并且还具有Transactional(Requires_new),那么每次重试完成时,它会创建一个新事务还是使用现有事务?

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?

@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);
}

这里实际会发生什么?

推荐答案

每次都会创建新交易。
它与从spring上下文获取服务和调用方法N次相同。每个调用都会创建新的事务(使用您添加到服务或方法中的传播)。调用您的交易代理方法,将其称为代理,也重试该代理。另外,您的交易可能会超时,请在新的超时时间内重试尝试调用,而不是在一次超时中尝试N次

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

这篇关于春季新交易与可重试结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆