Lock monitoring observes thread blocking, lock ownership, and lock-holding duration during execution. It helps investigate methods that appear to wait for themselves or spend less CPU time than total execution time. section 7.2
Use the investigation to answer these questions:
- Which threads are blocked, and which threads block them? section 7.2
- Which monitor object causes the blocking, and does the same object affect multiple threads? section 7.2
Producer and consumer contention
Start lock profiling in VisualVM with the Locks button, then expand a thread to inspect its monitors. One result showed a producer blocked by an ArrayList monitor while the consumer acquired that same monitor 3,698 times. The matching monitor reference connected both threads and revealed reciprocal blocking around a synchronized block. section 7.2
