-->

Lock analyser for Java application

2020-06-22 05:35发布

问题:

I have two versions of a Java application which use different concurrency logic.
I want to analyze and compare their performance (such amount of time a lock was acquired etc.) so that I can use the better one.

I found out a tool IBM Lock Analyzer for Java but it is neither open source nor JDK version independent.
It requires an IBM®-supplied Java™ SDK or JRE.

Another tool also from IBM is Multicore Software Development Kit and has the following problem

"The testing and analysis tool of MSDK runs on Sun JDK, except the lock analysis tool. The performance tool requires an IBM JDK."

So can anybody recommend any such lock analysis tool which works with Sun/Oracle Java?

回答1:

Here's a trick I've used a number of times to find lock contention in production environments from the command line:

watch -n1 'jstack [pid] | grep -A 1 BLOCKED | grep -v BLOCKED | grep -v \\-\\-'

Not only is it free, there's virtually no overhead. It won't give you stats or a nice UI of course, however it makes real-time locking issues obvious in a visual way. Essentially this is sampling every second to find blocked threads. With enough server load you should be able to make a comparison.

YourKit is a good commercial option.