中斷執行程序線程的正確方法是什麼? 我有這樣的: 線程類名工人與方法:如何中斷執行程序線程
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