不限次数重试
while(true) {
try {
// 执行可能抛出异常的操作
break;
} catch (Exception e) {
log.info("尝试失败,当前重试次数:" + i + " -----异常:" + e);
}
}
限制次数重试
int i = 0;
int tryTimes = 10;
while(true) {
try {
// 执行可能抛出异常的操作
break;
} catch (Exception e) {
if (i == tryTimes - 1) {
// 可以抛出RuntimeException退出,也可以break跳出循环
throw new RuntimeException("尝试已达到最大次数" + tryTimes, e);
} else {
log.info("尝试失败,当前重试次数:" + i + " -----异常:" + e);
}
}
i++;
}
PREVIOUSYAML配置中引用其它变量
NEXTSwagger使用