@Retryable spring重试注解使用

在类上增加@Retryable注解 application 增加@EnableRetryable注解 value 判断何种报错 maxAttempts指最大重试次数 backoff 为延时时间

代码实例

int i=0;
long startTime = System.currentTimeMillis();

@Retryable(
value = {Exception.class},
maxAttempts = 2,
backoff = @Backoff(delay = 6000)
)
public void dosome(){
while (true){
this.a(startTime);
System.out.println("没报错");
break;
}
}



public void a(Long a){
long endTime = System.currentTimeMillis();
i++;
if(endTime - a<5000){
System.out.println("第"+i+"次调用");
int v = 1/0;
}
System.out.println("第"+i+"次调用");
System.out.println("成功调用");

}
posted @ 2022-06-23 16:42  老小包的博客  阅读(123)  评论(0编辑  收藏  举报