源码注释
* @param mayInterruptIfRunning {@code true} if the thread executing this
* task should be interrupted; otherwise, in-progress tasks are allowed
* to complete
翻译成如下:
mayInterruptIfRunning
为true,该task
正在执行,这个task
应该被中断;
mayInterruptIfRunning
为false,该task
正在执行,这个task
将会继续执行到完成。
加深理解
做四个测试
mayInterruptIfRunning
为true,cancel 正在执行的taskmayInterruptIfRunning
为false,cancel 正在执行的taskmayInterruptIfRunning
为true,cancel 还没有执行的taskmayInterruptIfRunning
为false,cancel 还没有执行的task
测试代码
@Test
public void test() throws ExecutionException, InterruptedException {
ExecutorService pool =Ex