实例:
不生效的原因:

/**
 * 1、简单任务示例(Bean模式)
 */
@XxlJob("demoJobHandler")
public ReturnT<String> demoJobHandler(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");

    for (int i = 0; i < 5; i++) {
        try {
            XxlJobLogger.log("beat at:" + i);
            System.out.println("第"+i+"次");
            TimeUnit.SECONDS.sleep(3);
        }catch (Exception e){
           e.printStackTrace();
        }
    }
    return ReturnT.SUCCESS;
}

xxl-job超时任务无效原因解决方法1.png

实例:正确写法

/**
 * 1、简单任务示例(Bean模式)
 */
@XxlJob("demoJobHandler")
public ReturnT<String> demoJobHandler(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");

    for (int i = 0; i < 5; i++) {
        try {
            XxlJobLogger.log("beat at:" + i);
            System.out.println("第"+i+"次");
            TimeUnit.SECONDS.sleep(3);
        }catch (Exception e){
            if (e instanceof InterruptedException){
                throw e;
            }
        }
    }
    return ReturnT.SUCCESS;
}

xxl-job超时任务无效原因解决方法2.png

Last modification:October 16, 2020
如果觉得这篇技术文章对你有用,请随意赞赏