als der Titel.nach Abfangen "InterruptedException", warum "Thread.currentThread(). IsInterrupted()" Wert ist falsch?
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println(Thread.currentThread().isInterrupted()); //print false, who reset the interrupt?
}
}
});
thread.start();
TimeUnit.SECONDS.sleep(1);
thread.interrupt();
}
nach "InterruptedException", warum "Thread.currentThread(). Unterbrochen wird()" 's-Wert ist falsch zu kontrollieren?
Dieser Artikel kann Ihnen helfen, diesen Mechanismus zu verstehen und eine Antwort auf die Frage finden: [Was tun Sie, mit InterruptedException?] (Http://www.yegor256.com/2015/10/20/interrupted-exception.html) – yegor256