InterruptedException in Java — What It Means and How to Fix It

What Java's InterruptedException means and how to fix it.

Published November 3, 2026

InterruptedException is thrown when a thread that is waiting, sleeping or blocked is interrupted by another thread. It is a signal to stop what you are doing.

What it means and why it happens

Methods such as Thread.sleep, wait and BlockingQueue.take can throw it. Handling it properly matters for clean shutdowns.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
java.lang.InterruptedException: sleep interrupted

Practical examples

Code that triggers it

Thread.sleep(1000);   // must handle the checked exception

The fix

try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();   // restore the flag
    return;
}

ExecutorService shutdown

executor.shutdown();
if (!executor.awaitTermination(5, TimeUnit.SECONDS)) executor.shutdownNow();

Common mistakes

  • Swallowing it with an empty catch.
  • Not restoring the interrupt flag.
  • Ignoring cancellation requests.

Key takeaways

  • InterruptedException: InterruptedException is thrown when a thread that is waiting, sleeping or blocked is interrupted by another thread.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Why restore the flag?

So callers up the stack can see the thread was interrupted.

How do I find which line caused InterruptedException?

The error message and stack trace show the file and line; start there and work backwards.

More Java articles