wait/notify vs Condition.await/signal
Fast recall
Quick revision
Core answer
Understanding of the evolution from intrinsic locks to explicit locks, and the practical benefits of Condition over wait/notify.
Forgetting that wait() must always be called in a loop to guard against spurious wakeups, and that the same is true for Condition.await().
Point out that a single Lock can have multiple Condition objects, enabling selective notification — impossible with intrinsic wait/notify which share one condition queue per object.
Interview-ready guide
Interview answer
wait()/notify() uses one shared wait queue for all waiters — Condition objects create separate queues, making wakeups precise.
Problem with wait/notify:
notify()wakes an arbitrary thread — might wake a producer when you need a consumernotifyAll()wakes everyone but most immediately go back to sleep — wasted context switches
Condition objects:
- Created from ReentrantLock:
Condition notFull = lock.newCondition() - Producers
awaitonnotFull, consumers onnotEmpty—signal()wakes exactly one from the correct queue
The while loop pattern (mandatory):
while (!condition) await()— spurious wakeups are real; usingifinstead ofwhilecauses correctness bugsCondition.await()supports timed waiting that returnsfalseon timeout —Object.wait(millis)returns void and can't distinguish timeout from notification
I recommend Condition objects with ReentrantLock for all producer-consumer patterns. wait()/notify() with synchronized is functional but less precise and harder to reason about correctly.
wait/notify vs Condition.await/signal
Direct Answer
Both implement the monitor pattern for thread cooperation, but Condition is strictly more powerful. It supports multiple condition queues per lock, timed waits with interruption control, and integrates cleanly with ReentrantLock. Prefer Condition for new code that needs explicit locking.
Common Mistakes & Pitfalls
Forgetting that wait() must always be called in a loop to guard against spurious wakeups, and that the same is true for Condition.await().
Check your understanding
Answer these without looking back at the article.
- Why must await/wait always be called inside a while loop?
- How does ArrayBlockingQueue use Condition internally?
- What is awaitUninterruptibly() and when is it useful?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.