Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Explain how thread interruption works in Java, including the difference between Thread.interrupted() and isInterrupted().

Calling interrupt() on a thread only sets its interrupt status; it does not stop the thread. Blocking methods such as sleep(), wait(), join() and BlockingQueue.take() notice the status, clear it and throw InterruptedException, while other code must check the status itself, so interruption is cooperative. Thread.interrupted() is a static method that returns the current thread's status and clears it, and isInterrupted() is an instance method that reads a thread's status without clearing it. Executors use interruption to cancel work, through shutdownNow() and Future.cancel(true).

Why this question is asked

Interruption is Java's only standard way to ask a thread to stop what it is doing. Every graceful shutdown, every cancelled request and every timeout in an executor depends on it, and code that handles it badly produces threads that cannot be stopped. Interviewers ask about it to check that we know interruption is a request rather than a command, and to see whether we confuse the two methods with almost the same name. In this answer, we will recap the interrupt status, see how blocking methods react, compare Thread.interrupted() with isInterrupted(), write a loop that responds properly, and see how executors use all of this.

1A Quick Recap: The Interrupt Status

Every thread has a boolean flag called its interrupt status, false by default. Calling t.interrupt() from any thread sets t's flag to true. That is all it does. The target thread keeps running its current instruction; nothing is forcibly stopped, no lock is released and no exception is thrown into running code.

Java chose this design after the unsafe Thread.stop(), which killed a thread at an arbitrary point and could leave shared objects half-updated. With interruption, the thread being interrupted decides when and how to stop, at a point where its data is consistent. This is what cooperative cancellation means: one side asks, the other side agrees to check and respond.

2How Blocking Methods React

Methods that may block for a long time are the natural places to respond. Thread.sleep(), Object.wait(), Thread.join(), BlockingQueue.take() and put(), Future.get(), CountDownLatch.await() and Lock.lockInterruptibly() all declare throws InterruptedException. If the thread is interrupted while blocked in one of them, or is already interrupted when it calls one, the method clears the interrupt status and throws InterruptedException.

Java
Thread sleeper = new Thread(() -> {
try {
Thread.sleep(60_000);
} catch (InterruptedException e) {
System.out.println("woken early"); // woken early
System.out.println(Thread.currentThread().isInterrupted()); // false: the flag was cleared
}
});
sleeper.start();
sleeper.interrupt();
Step throughAn interrupt reaching a blocked thread
Controller threadWorker threadBlockingQueue
take(): queue empty, worker blocks
worker.interrupt(): flag = true
take() wakes, clears flag, throws InterruptedException
catch: restore flag or exit the loop

4 messages in order. Play them, or step through them one at a time.

The exception carries the signal; the flag is cleared at that moment.

Notice the second line of output. The exception carries the signal, and the flag is reset to false at the moment it is thrown. So whoever catches InterruptedException now holds the only record that an interruption happened. If they ignore it, the request to stop is lost. Not every blocking call responds, though: acquiring a synchronized lock and reading a classic java.io socket stream do not react to interruption.

3Thread.interrupted() Versus isInterrupted()

The two methods differ in two ways, and both matter. Thread.interrupted() is static, so it always asks about the current thread, and it clears the flag as it reads it. isInterrupted() is an instance method, so we can ask about any thread, and it only reads.

Java
Thread.currentThread().interrupt(); // set our own flag
System.out.println(Thread.currentThread().isInterrupted()); // true
System.out.println(Thread.currentThread().isInterrupted()); // true: reading does not clear
System.out.println(Thread.interrupted()); // true, and the flag is now cleared
System.out.println(Thread.interrupted()); // false
The two methods side by side
MethodStatic?Which threadClears the flag?
Thread.interrupted()YesAlways the current threadYes
t.isInterrupted()NoThread t, any threadNo
t.interrupt()NoThread tNo, it sets it to true

So isInterrupted() is what we use in a loop condition, where we want to check and keep the flag set for code further up. Thread.interrupted() is for the rare case where we deliberately consume the signal, for example just before throwing InterruptedException ourselves. A common bug is to call interrupted() in a check and accidentally erase a request that an outer loop also needed to see.

4Writing Code That Responds to Interruption

Because interruption is cooperative, code that runs for a long time has two duties: check the flag in loops that do not block, and handle InterruptedException properly when it does block. Handling it properly means either letting it propagate by declaring throws InterruptedException, or, when that is not possible, restoring the flag with Thread.currentThread().interrupt() and returning.

Java
void processAll(BlockingQueue<Job> queue) {
while (!Thread.currentThread().isInterrupted()) { // check for CPU-only stretches
try {
Job job = queue.take(); // responds while blocked
job.run();
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // restore the flag for our caller
return; // and stop
}
}
}

Restoring the flag matters because our method may be called from code that also checks it, such as an executor's worker loop. Swallowing the exception without restoring the flag leaves a thread that can never be stopped by interruption again.

5How Executors Use Interruption

The executor framework builds cancellation on top of this mechanism. ExecutorService.shutdownNow() interrupts every worker thread that is running a task, and returns the tasks still waiting in the queue. Future.cancel(true) interrupts the thread running that task, while cancel(false) only prevents a task from starting if it has not started yet. Likewise, an executor's awaitTermination() simply waits; it only succeeds in time if the interrupted tasks actually respond.

But there is a catch: all of this depends on the task code. A task that never checks the flag or swallows InterruptedException will keep running after shutdownNow(), and awaitTermination() will time out. So responding to interruption is not an optional nicety; it is what makes our tasks cancellable at all.

6Follow-up questions

Why does catching InterruptedException clear the flag?

Because the exception itself now carries the information, and the design assumes the catcher will act on it. Clearing it means a thread that has handled an interruption can go on to use blocking methods normally. The cost is that a catcher who ignores the exception loses the request completely, which is why restoring the flag is the standard practice.

Does interrupt() affect a thread that is waiting for a synchronized lock?

No. Waiting to enter a synchronized block cannot be interrupted; the flag is set, and the thread will see it only after it gets the lock and later checks. If we need lock waiting to be cancellable, we use ReentrantLock.lockInterruptibly() or tryLock() with a timeout.

Is it ever right to swallow InterruptedException?

Only when our code owns the thread and the interruption is the signal to end its work, for example the run loop of a thread we created, where we exit cleanly and there is no caller left to inform. In library or task code, we do not own the thread, so we restore the flag or rethrow.

7Conclusion

In this answer, we saw that interrupt() only sets a flag, and the interrupted thread decides when to stop, which is why interruption is cooperative. Blocking methods such as sleep, wait, join and take throw InterruptedException and clear the flag, so the catcher must restore it or propagate it. Thread.interrupted() is static, reads the current thread and clears the flag, while isInterrupted() reads any thread without clearing it. Executors rely on this for shutdownNow() and Future.cancel(true), so our tasks must respond for cancellation to work.

What to say in the interviewAbout 80 seconds aloud

Open with

Interrupting a thread doesn't stop it. Calling interrupt sets a boolean interrupt status on the target thread, and it's up to that thread to notice and decide to stop, so interruption is cooperative.

Then, if they want more

Java chose that after Thread.stop, which could kill a thread in the middle of updating shared state. The places where a thread usually notices are blocking methods like sleep, wait, join, BlockingQueue.take and Future.get. If the thread is interrupted while blocked in one, or before it calls one, the method clears the flag and throws InterruptedException.

Because the flag is cleared, whoever catches that exception should either let it propagate or call Thread.currentThread().interrupt() to restore the flag, and then stop what it's doing. In code that doesn't block, like a CPU loop, I check Thread.currentThread().isInterrupted() in the loop condition.

On the two methods: Thread.interrupted is static, it always checks the current thread, and it clears the flag as it reads it. isInterrupted is an instance method, it can check any thread, and it doesn't clear anything, so it's the one I use in loop checks.

Executors build cancellation on this: shutdownNow interrupts all running workers, and Future.cancel(true) interrupts the thread running that task, but both only work if the task code actually responds.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain how thread interruption works in Java, including the difference between...": https://scrivio-interview-library.netlify.app/java/threads/385064c655/