Quick revision
The short answer
When a blocking call such as queue.take() or Thread.sleep() throws InterruptedException, it clears the thread's interrupt status first. An empty catch block therefore erases the only signal that the executor's shutdownNow() sends, so the task carries on looping, the pool never terminates, and shutdown waits until it times out. The fix is to restore the flag with Thread.currentThread().interrupt() and stop the work, or to let the exception propagate.
What to remember
In this answer, we saw that blocking methods clear the interrupt status when they throw InterruptedException, so an empty catch block erases the only signal that shutdownNow() sends. The worker loops back into a blocking call, the pool never terminates, and awaitTermination times out. The fix is to restore the flag with Thread.currentThread().interrupt() and stop, or to let the exception propagate, and to make never swallowing InterruptedException a rule enforced by static analysis and a shutdown test.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
When a blocking call such as queue.take() or Thread.sleep() throws InterruptedException, it clears the thread's interrupt status first. An empty catch block therefore erases the only signal that the executor's shutdownNow() sends, so the task carries on looping, the pool never terminates, and shutdown waits until it times out. The fix is to restore the flag with Thread.currentThread().interrupt() and stop the work, or to let the exception propagate.
Why this question is asked
A service that will not shut down cleanly is more than an annoyance. Deployments stall, Kubernetes eventually kills the pod with SIGKILL after the grace period, in-flight work is cut off at a random point, and rolling restarts take minutes instead of seconds. Very often the cause is one innocent-looking line: catch (InterruptedException e) {}. Interviewers ask this because it tests whether we know how Java's cooperative cancellation works. In this answer, we will recap what interruption is, reproduce the hang, see exactly why the empty catch causes it, apply the two correct fixes, and cover the rule that keeps it from coming back.
1A Quick Recap of Thread Interruption
Java cannot safely force a thread to stop in the middle of what it is doing. Instead it uses interruption, a polite request. Every thread has a boolean interrupt status. Calling thread.interrupt() sets it to true. The thread is expected to notice and stop on its own.
Threads notice in two ways. Code can check the flag with Thread.currentThread().isInterrupted(). And blocking methods such as Thread.sleep, Object.wait, BlockingQueue.take and Future.get check it for us: if the flag is set, or becomes set while they wait, they throw InterruptedException. Here is the detail that matters for this bug: when they throw, they clear the flag. The exception is now the only record that an interrupt happened.
ExecutorService builds its shutdown on this. shutdown() stops accepting new tasks and lets running ones finish. shutdownNow() additionally calls interrupt() on every worker thread, and awaitTermination() waits until all workers have exited.
2Reproducing the Hang
Here is a typical background worker that drains a queue. It looks harmless.
The worker is blocked in queue.take() when shutdownNow() interrupts it. take() wakes up, clears the interrupt status and throws InterruptedException. The empty catch block does nothing, so the loop goes round again. The while condition checks isInterrupted(), but the flag was just cleared, so it returns false, and the worker calls take() again and blocks forever. awaitTermination() waits the full 30 seconds and returns false.
3Why the Empty Catch Breaks Shutdown
The interrupt carried one bit of information: please stop. It existed in two forms for a moment, first as the flag, then as the exception after take() cleared the flag. The empty catch threw the exception away, and with it the last copy of the request. From the worker's point of view nothing ever happened.
Notice that the loop's own check was correct. It was written to stop on interrupt. But that check relies on the flag, and the catch block destroyed the flag's replacement. This is why swallowing InterruptedException is never neutral: it does not just ignore an error, it cancels a cancellation.
8 messages in order. Play them, or step through them one at a time.
The only signal to stop is erased in the catch block.
4Fix 1: Restore the Flag and Stop
When we cannot throw InterruptedException from our method, as in a Runnable whose run() method does not declare it, we restore the flag and leave the loop.
Restoring the flag matters even when we also break out. The reason is that our code may not be the last thing to run on this thread. The executor's own code, or a caller further up, may check the flag to decide what to do, and they should see the same request we saw.
5Fix 2: Let the Exception Propagate
If the work is a Callable, or a method we control, the simplest correct choice is not to catch InterruptedException at all and declare it with throws. The exception then ends the task, and the executor's worker thread handles it.
A third option is to wrap and rethrow, for example as a custom unchecked exception, but then we should still restore the flag before throwing, because the wrapper hides the interrupt from code that checks the flag.
6Making It a Team Rule
The rule is short: never swallow InterruptedException silently. Every catch either rethrows it, or restores the flag and stops what it is doing. Logging it and carrying on is still swallowing.
This is easy to check automatically. Sonar has a rule that flags catch blocks for InterruptedException that neither rethrow nor re-interrupt (check the rule key in your version), and Error Prone and PMD offer similar checks. It is also worth testing shutdown itself: a test that starts the component, calls its stop method and asserts that awaitTermination returns true within a couple of seconds would have caught this bug before production.
7Follow-up questions
Why does Java clear the flag when it throws InterruptedException?
Because the exception now represents the interrupt. If the flag stayed set, the very next blocking call in a cleanup or logging path would throw again immediately, which would make it hard to do any orderly work after an interrupt. The design expects the code that catches the exception to decide, and to restore the flag if it does not fully handle the request.
What if the task is busy computing and never blocks?
Then no InterruptedException is thrown at all, and the task must check Thread.currentThread().isInterrupted() itself at sensible points, for example once per loop iteration. A long CPU-bound loop that never checks will also make shutdownNow ineffective.
Why not just use Thread.interrupted() in the loop condition?
Thread.interrupted() checks the flag and also clears it, which is the same trap in another form. For a loop condition we use isInterrupted(), which only reads the flag.
8Conclusion
In this answer, we saw that blocking methods clear the interrupt status when they throw InterruptedException, so an empty catch block erases the only signal that shutdownNow() sends. The worker loops back into a blocking call, the pool never terminates, and awaitTermination times out. The fix is to restore the flag with Thread.currentThread().interrupt() and stop, or to let the exception propagate, and to make never swallowing InterruptedException a rule enforced by static analysis and a shutdown test.
Open with
Interruption is how Java asks a thread to stop, and shutdownNow on an executor works by interrupting every worker. A blocking call like queue.take or Thread.sleep notices the interrupt and throws InterruptedException, and when it throws, it clears the thread's interrupt flag.
Then, if they want more
So at that moment the exception is the only record of the request. With an empty catch block, the task throws that away, goes round its loop, checks isInterrupted, which is now false, and blocks on take again. The worker never exits, so awaitTermination waits for its full timeout, and in Kubernetes the pod eventually gets killed hard.
The fix is either to let InterruptedException propagate, for example from a Callable, or, if I cannot throw it, to call Thread.currentThread().interrupt() in the catch to restore the flag and then break out of the loop and stop the work. Restoring the flag matters even if I stop, because code further up the stack may check it.
I would make never swallowing InterruptedException a team rule, enforce it with the Sonar or Error Prone check, and add a test that starts the component, stops it, and asserts the executor terminates within a couple of seconds.
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.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 "A thread pool task catches InterruptedException with an empty catch block. Shutdown of...": https://scrivio-interview-library.netlify.app/java/exceptions/46b8451903/