Java Concurrency Interview

Threads and lifecycle question 8 of 180 mid

What is the difference between BLOCKED, WAITING and TIMED_WAITING in a thread dump?

BLOCKED means the thread is trying to enter a synchronized block whose monitor someone else owns. The dump names the owner, which makes lock contention and deadlock visible at a glance.

WAITING means the thread called Object.wait(), Thread.join(), LockSupport.park() or an untimed Condition.await(), and will stay there until something signals it. TIMED_WAITING is the same with a deadline.

The trap: a thread waiting on ReentrantLock shows as WAITING at LockSupport.park, never as BLOCKED, because the lock is implemented with AbstractQueuedSynchronizer rather than a monitor. If you grep a dump for BLOCKED to find contention, java.util.concurrent locks are invisible to you.

diagnostics lifecycle

Quiz yourself on Threads and lifecycle Suggest a correction