A locked thread is blocked at the entrance of a synchronized block because another thread currently holds the relevant monitor. The monitor permits only one thread to execute inside that restricted region at a time. A locked thread differs from a waiting thread: waiting begins after the monitor explicitly suspends a thread already inside the synchronized region. section 7.3
Figure 7.14 Locked versus waiting threads. A locked thread is blocked at the entrance of a synchronized block. The monitor won’t allow a thread to enter a synchronized block while another thread actively runs inside the block. A waiting thread is a thread that the monitor has explicitly set to the blocked state. The monitor can make any thread inside the synchronized block it manages wait. The waiting thread can continue its execution only after the monitor explicitly tells it that it can proceed.
Use this comparison to distinguish contention at a synchronized block’s entrance from explicit waiting inside the block. section 7.3
In a producer–consumer application:
- A consumer can wait when the list is empty, allowing a producer to acquire the monitor and add a value. section 7.3
- A producer can wait when the list reaches its capacity, allowing a consumer to remove values. section 7.3
- Profiling may show fewer lock events but longer blocking periods, so frequency and duration both matter. section 7.3
