这是一种内部机制,但是如果您像下面这样添加try nad catch,将从sleep方法中抛出interruptedexception(因为线程已被shutdown方法中断),因此shutdown方法确实会更改线程状态。
public static void main(String[] args) throws InterruptedException {
ExecutorService service = Executors.newSingleThreadExecutor(r -> {
final Thread thread = new Thread(r);
thread.setDaemon(false);
return thread;
});
service.submit(() -> {
try {
while (true) {
Thread.sleep(1000);
System.out.println("Done: " + Thread.currentThread().isInterrupted());
}
} catch (Exception e1) {
e1.printStackTrace();
}
});
Thread.sleep(3000);
service.shutdownNow();
}