xuxueli / xxl-job

A distributed task scheduling framework.(分布式任务调度平台XXL-JOB)
http://www.xuxueli.com/xxl-job/
GNU General Public License v3.0
27.39k stars 10.84k forks source link

“InterruptedException” 异常,是不用往外抛了么?版本2.3.0 #2206

Open showlist opened 3 years ago

showlist commented 3 years ago

`@Component public class DemoGlueJobHandler extends IJobHandler {

@Autowired
private TestService testService;

@Override
public void execute() throws Exception {
    try{
        testService.testPrint();
    }catch (Exception e){
    }
}

}` 在调度中心和管理后台能正常停用任务,采用的是GLUE(Java)模式

showlist commented 3 years ago

任务终止时通过 “interrupt” 执行线程的方式实现, 将会触发 “InterruptedException” 异常。因此如果JobHandler内部catch到了该异常并消化掉的话, 任务终止功能将不可用。

因此, 如果遇到上述任务终止不可用的情况, 需要在JobHandler中应该针对 “InterruptedException” 异常进行特殊处理 (向上抛出) , 正确逻辑如下: try{ // do something } catch (Exception e) { if (e instanceof InterruptedException) { throw e; } logger.warn("{}", e); } 而且,在JobHandler中开启子线程时,子线程也不可catch处理”InterruptedException”,应该主动向上抛出。

showlist commented 3 years ago

不是说要向上抛出才能停止么?

yanhua-volvo commented 11 months ago

同样的问题