aop实现失败重试从spring官方文档上摘录下来的,可以实现并发重试

public class ConcurrentOperationExecutor implements Ordered {

private static final int DEFAULT_MAX_RETRIES = 2;

private int maxRetries = DEFAULT_MAX_RETRIES;
private int order = 1;

public void setMaxRetries(int maxRetries) {
    this.maxRetries = maxRetries;
}

public int getOrder() {
    return this.order;
}

public void setOrder(int order) {
    this.order = order;
}

public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
    int numAttempts = 0;
    PessimisticLockingFailureException lockFailureException;
    do {
        numAttempts++;
        try {
            return pjp.proceed();
        }
        catch(PessimisticLockingFailureException ex) {
            lockFailureException = ex;
        }
    } while(numAttempts <= this.maxRetries);
    throw lockFailureException;
}

}

相关文章:

  • 2021-11-14
  • 2021-12-19
  • 2021-09-18
  • 2021-10-19
  • 2021-07-17
  • 2019-11-12
  • 2021-06-02
猜你喜欢
  • 2019-01-12
  • 2020-06-23
  • 2019-12-04
  • 2021-07-02
  • 2021-12-30
  • 2020-10-16
  • 2018-09-25
  • 2021-06-03
相关资源
相似解决方案