Difference between WAIT and BLOCKED thread states
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding the Difference Between WAIT and BLOCKED Thread States
Thread management is critical in concurrent programming where multiple threads operate simultaneously. Understanding thread lifecycle states, particularly WAIT and BLOCKED, is vital for optimizing performance and troubleshooting applications. Let's delve into these thread states, highlighting their differences, technical details, and usage in programming.
Thread Lifecycle Overview
In Java, a thread passes through several states:
- NEW: Created but not yet started.
- RUNNABLE: Executing in the JVM but possibly waiting for other resources.
- BLOCKED: Waiting for a monitor lock.
- WAITING: Waiting indefinitely for another thread to perform a particular action.
- TIMED_WAITING: Waiting for a specified period.
- TERMINATED: Completed execution.
BLOCKED Thread State
- Definition: A BLOCKED thread is waiting to acquire a monitor lock to enter or re-enter a synchronized block or method. It occurs when one thread attempts to access a synchronized section of code already acquired by another thread.
- When It Occurs:
- Example: Consider a synchronized block. If Thread A holds a lock, and Thread B tries to access the same block, Thread B transitions to the BLOCKED state until Thread A releases the lock.
- Key Characteristics:
- Ownership: The thread lacks the lock necessity to proceed.
- Duration: Remains BLOCKED until the lock becomes available.
- Nature: Typically short-lived unless contention for the lock is high.
WAIT Thread State
- Definition: A WAITING thread waits indefinitely for another thread to perform a specific action — such as notifying it to resume execution.
- How to Enter:
- Methods like
Object.wait(),Thread.join(), orLockSupport.park().
- When It Occurs:
- Example: A thread calling
wait()on a shared object releases the object lock and transitions to the WAIT state until another thread invokesnotify()ornotifyAll()on the same object.
- Key Characteristics:
- Ownership: Does not hold the object lock it waits on.
- Control: Requires context switching control, i.e., another thread's
notify(). - Nature: May lead to indefinite waiting without external intervention.
Technical Comparison
Below, we summarize the key differences between WAIT and BLOCKED states:
| Property | BLOCKED | WAIT |
| Trigger | Waiting for a monitor lock | Calling wait(), join(), or park() on a condition |
| Holding a Lock | No | No |
| Duration Control | Controlled by lock availability | Controlled by external actions like notify() |
| State Transition | Transitions to RUNNABLE when the lock is acquired | Transitions to RUNNABLE upon receiving notify() or timeout |
| Nature | Typically short-lived unless resource contention occurs | Potentially indefinite |
| Resolution | Depends on lock release by another thread | Requires explicit action (notify or timeout) by another thread |
Advanced Topics: Synchronization and Deadlocks
- Synchronization: Ensures that only one thread can execute a particular section of code at a time. While waiting for synchronization, a thread may enter BLOCKED or WAIT states.
- Deadlocks: Occur when two or more threads block each other indefinitely, waiting for resources held by each other. Analyzing WAIT and BLOCKED states can detect and prevent deadlocks.
Practical Usage and Observations
- Performance: High frequency of BLOCKED threads may indicate resource contention or suboptimal lock usage.
- Design: Effective thread design minimizes WAIT and BLOCKED times, promoting efficient resource utilization.
- Debugging: Tools such as thread dumps highlight WAIT and BLOCKED states, aiding in diagnosing performance bottlenecks.
Understanding thread states, particularly WAIT and BLOCKED, empowers developers to create responsive and efficient multithreaded applications. Mastery of these concepts leads to better resource management, optimized performance, and minimal contention — essential components of high-quality software development.

