中断执行者线程的正确方法是什么?我有这个:名称为Worker的线程类和方法:
public void run() {
while(!(Thread.currentThread().isInterrupted()){
System.out.println("work " + Thread.currentThread().getName() + ":" + Thread.currentThread().isInterrupted());
}
}
主要课程:
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
Worker worker = new Worker();
executorService.execute(worker);
我尝试打电话worker.interrupt();
,或者executorService.shutdownNow();
但我的线程继续并且 isInterrupted() 是错误的。