调用接口,设置重试次数

调用接口有时候可能因为网路原因,链接不上,解决:设置重试次数

//任务重复请求次数
public static final int RETRY_NUM = 3;              


  for (int i = 0; i < RETRY_NUM; i++) {

try {
//调用接口
        StockQuerySafClient stockQuerySafClient = ContextSafBeanUtil.getStockQuerySafClient();
               skuStockList = stockQuerySafClient.queryStockJdBySkuIdsSaf(wids);
               break;
} catch (Throwable e) {
log.error("第" + i + 1 + "次调用接口服务失败", e);
if (i == RETRY_NUM - 1) {
//错误状态封装
executionContext.getWorkerFatalMap().put(this.workId ,  Constants.WS_EXP_JITSTOCK);


workLogSheet = new WorkLogSheet();
workLogSheet.setTaskId(this.taskId);
wlsList = new ArrayList();
wlsList.add(workLogSheet);


try {
taskService.insertWorkerLog(workerLog);
} catch (SQLException e1) {
log.error("任务" + this.taskId + "插入日志发生异常");
}


try {
taService.insertWorkLogBatch(wlsList);
} catch (SQLException e2) {
log.error("任务" + this.taskId
+ "插入错误日志日志发生异常");
}
}

}
}

你可能感兴趣的:(java,js基础)