public static void main(String[] args) {
String s = tryAgain();
System.out.println(s);
}
private static String tryAgain() {
int retry = 10; //重试次数
int callCount = 0;
while (true){
try {
//String result = null;
String result = your method(); //换成你要调用的方法
if(StringUtils.isNotBlank(result)){
return result;
}else{
throw new Exception("result null");
}
} catch (Exception e) {
callCount++;
logger.error("http request error {}", e);
if(callCount > retry){
return null;
}
try {
Thread.sleep(1000L);
} catch (InterruptedException var3) {}
}
}
}
异常发生重试机制。
最新推荐文章于 2024-01-02 13:00:00 发布