中断执行程序线程的正确方法是什么? 我有这样的: 线程类名工人与方法:如何中断执行程序线程
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( )是错误的。
检查了这一点,其可能是一个可能的重复http://stackoverflow.com/questions/7142665/why-does-thread-isinterrupted-always-return-false – GETah