Java Thread Waiting State and InterruptedException Handling

1Z0-829 By islever Editorial Last updated

Managing concurrent code execution

Short answer

D A thread in waiting state must handle InterruptedException.

Question

Which statement is true?
  1. IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
  2. A thread in waiting state consumes CPU cycles.
  3. After the timed wait expires, the waited thread moves to the terminated state.
  4. A thread in waiting state must handle InterruptedException. Correct Answer

Key Takeaways

The core concept tested is the interaction between thread states and interrupts; the common trap is assuming waiting threads consume CPU or transition incorrectly upon timeout.

This question examines the behavior of Java threads in the waiting state, specifically focusing on interrupt handling. It establishes that while waiting, a thread must handle InterruptedException if interrupted.

Common mistake: Candidates often mistakenly believe that waiting threads consume CPU cycles (Option B) or that timeouts lead directly to termination (Option C), ignoring the standard state transitions back to runnable.

Expert Analysis

Why the Answer Is Correct

Option D is correct because any thread entering a waiting state via methods like Thread.sleep, Object.wait, or LockSupport.parkNanos can be interrupted by another thread calling interrupt. When this happens, the waiting method throws an InterruptedException, which the thread must either catch and handle or declare in its signature. This is a fundamental contract of Java concurrency.

Why the Other Options Are Wrong

Option A is incorrect because moving a thread from waiting to runnable is a normal lifecycle event triggered by notify, notifyAll, or time expiration; it does not throw an IllegalStateException. Option B is false because threads in the waiting state are inactive and do not consume CPU cycles until they become runnable. Option C is incorrect because when a timed wait expires, the thread moves to the runnable state (to compete for the lock/CPU), not the terminated state, unless the run method completes during that time.

Community Comment Notes

The community consensus strongly supports D, with multiple users confirming that waiting threads do not consume CPU and that interrupts result in exceptions. As ASPushkin noted, "A thread is inactive when in the blocked or waiting state... D is correct" regarding exception handling. Comments consistently refute the idea that waiting implies CPU usage or immediate termination.

Exam Strategy

Remember that 'Waiting' means the thread is idle until notified or interrupted. Always check if options imply active resource consumption (like CPU) for waiting states—that is usually false. For interrupts, always expect an Exception.

Frequently Asked Questions

Does a thread in waiting state consume CPU?

No. Threads in waiting or blocked states are inactive and yield the CPU to other threads until they become runnable.

Where does a thread go after a timed wait expires?

It moves to the runnable state to contend for the monitor lock or CPU resources, not directly to terminated.

More 1Z0-829 FAQ →

Community Votes

D
100%

100% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 2 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 2

  1. ASPushkin 👍 1 Answered D
    A. IllegalStateException is thrown if a thread in waiting state is moved back to runnable. false it moves back to runnable as a result of notify(), notifyAll() or time elapsed or finish the thread (join()) B thread in waiting state consumes CPU cycles. false A thread is inactive when in the blocked or waiting state. When in these states, the thread does not consume any CPU cycles. D. A thread in waiting state must handle InterrupedException. true public void run() In inheritance method must not throw new or checked exception So any checked exception has to be handled inside Object.join Object.wait Thread.sleep all of them throw InterruptedException
  2. xplorerpj 👍 1 Answered D
    D is correct

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to 1Z0-829 Study Guide