A thread's interrupted flag is cleared the instant InterruptedException is thrown, so a handler that only logs and moves on hides the interruption from the rest of the code; re-calling interrupt() restores that flag.
Thread worker = new Thread(() -> {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
System.out.println("Caught: " + e.getClass().getSimpleName());
Thread.currentThread().interrupt();
}
System.out.println("Interrupted flag restored: " + Thread.currentThread().isInterrupted());
});
worker.start();
worker.interrupt();
worker.join();
Caught: InterruptedException
Interrupted flag restored: true
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27