0
我有以下這段代碼對我來說很奇怪。日誌消息顯示當前線程未中斷,爲什麼?什麼時候線程的中斷標誌被設置?
final BlockingQueue<String> queue = new ArrayBlockingQueue<String>(10);
Thread thread = new Thread() {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
LOG.info("start to take");
String next = queue.take();
LOG.info(next);
} catch (InterruptedException e) {
LOG.info(e + "");
LOG.info("IsInterupted:"
+ Thread.currentThread().isInterrupted());
continue;
}
}
}
};
thread.start();
Thread.sleep(1000);
thread.interrupt();