xxl-job 偶发性 job execute timeout

vngu2lb8  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(70)

Please answer some questions before submitting your issue. Thanks!

Which version of XXL-JOB do you using?

2.3.0

Expected behavior

handler.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 futureTask = new FutureTask(new Callable(){
@OverRide
public Boolean call() throws Exception {

// 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();
}`
tmb3ates

tmb3ates1#

现场情况 3秒,三次调度日志 出现 job execute timeout ,但是没有log.info日志,看起来像未执行FutureTask 中的handler.execute();
然而futureTask.get(triggerParam.getExecutorTimeout(), TimeUnit.SECONDS);抛出了TimeoutException

zpgglvta

zpgglvta2#

我遇到的是我的调度执行时长大于了我设置的超时时长,修改了超时时长就不报超时了

相关问题