I'm considering switching from synchronized
to a ReadWriteLock
. Before doing it, I would like to check if it's worth it.
ThreadMXBean
and ThreadInfo
provide information about overall thread blocked count and time. Those blocks can be caused by multiple monitors. Is there a way to measure block statistics given a particular monitor object?
Yes, it is possible using JVMTI.
What is you need is to write a native agent that handles a pair of events:
Both events accept jthread
and jobject
arguments that correspond to a thread acquiring the monitor and the monitor object itself.
Here is a sample code for the contention profiler agent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With