liveBook · Manning

Lock monitoring

As explained in Troubleshooting Java, Second Edition

Lock monitoring is the observation of thread blocking, lock ownership, and lock-holding duration during program execution.

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

How Troubleshooting Java, Second Edition covers it

How deep it goes
Explains instrumented profiling down to monitor references and reciprocal blocking, while sampling alone remains insufficient.
Examples
Uses producer-consumer threads, an ArrayList monitor, VisualVM lock results, and JProfiler event histories.
What you can do after
Diagnose lock contention by correlating blocked threads, monitor references, ownership counts, event timing, and duration.
How it connects
Connects thread blocking, monitors, synchronized blocks, and execution profiling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.