9
系统是如何做到,停止一个运行中的任务线程呢,我看了源码,但是发现代码里边只是给任务线程设置了一个终止标记interrupt,但是这样并不能停止正在运行的线程,除非线程中有wait,sleep等阻塞操作,希望大神给指点一下。
if (triggerParam.getExecutorTimeout() > 0) {
// limit timeout
Thread futureThread = null;
try {
FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() {
@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(); //这里只是给线程打了一个停止的标记,并不会中断正在运行的任务
}