2.3.0
Expected behaviorhandler.execute();输出耗时日志,
Actual behavior业务日志未输出,taskJobHandler内未有日志输出 执行超时 job execute timeout
Steps to reproduce the behavior重现困难,目前配置单机,任务181条,每个任务每秒执行一次,超时设置1s
Other information超时源码
`if (triggerParam.getExecutorTimeout() > 0) {
Thread futureThread = null;
try {
FutureTask
// init job context
XxlJobContext.setXxlJobContext(xxlJobContext);
handler.execute();
return true;
}
});
futureThread = new Thread(futureTask);
futureThread.start();
Boolean tempResult = futureTask.get(triggerParam.getExecutorTimeout(),
TimeUnit.SECONDS);
} catch (TimeoutException e) {
XxlJobHelper.log("<br>----------- xxl-job job execute timeout");
XxlJobHelper.log(e);
// handle result
XxlJobHelper.handleTimeout("job execute timeout ");
} finally {
futureThread.interrupt();
}`
` @XxlJob("taskJobHandler") public void taskJobHandler() throws Exception { String param = XxlJobHelper.getJobParam(); long logId = LogUtils.getLogId(); StrategyJobParams strategyJobParams = objectMapper.readValue(param, StrategyJobParams.class); //计算期望执行几次 int expectTime = strategyJobParams.getExpectTime();
if (expectTime < minTime) {
int num = minTime / expectTime;
long start = System.currentTimeMillis();
for (int i = 0; i < num; i++) {
long startTime = System.currentTimeMillis();
long totalTime = startTime - start;
如果剩余时间小于期望执行时间,跳出
log.info("logId:[{}],[{}],总耗时:{}, 剩余时间{}",logId,strategyJobParams.getContract(), totalTime, (minTime - totalTime));
if (expectTime > (minTime - totalTime)) {
break;
}
try {
doNearStrategy(strategyJobParams.getContract(),logId, strategyJobParams);
} catch (Exception exception) {
log.error("logId:[{}],[{}],{}:策略执行异常", logId,strategyJobParams.getContract(), exception);
}
Long spendTime = System.currentTimeMillis() - startTime;
//计算当前时间范围还剩多少毫秒,大于0时做延时处理,保证任务均匀分布在这一秒内
int delayTime = expectTime - spendTime.intValue() - 5;
if (delayTime > 0) {
Thread.sleep(delayTime);
}
}
} else {
log.info("策略执行")
doNearStrategy(strategyJobParams.getContract(),logId, strategyJobParams);
}
XxlJobHelper.handleSuccess();
}`