在类上增加@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("成功调用");
}