4

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?

Alpine
  • 3,838
  • 1
  • 25
  • 18
Abhishek Anand
  • 247
  • 2
  • 10

1 Answers1

2

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.

WhiteFang34
  • 70,765
  • 18
  • 106
  • 111
  • I'll be looking into YourKit. BTW your method is for linux machines only and I forgot to mention that we have both linux and windows applications which we might need to analyse. – Abhishek Anand Mar 23 '11 at 04:16
  • 1
    Ah, ok. Two things to consider then if you're interested in the inexpensive approach to looking for lock contention under load: 1) you could install Cygwin to run the command I suggested or 2) you could still analyze on Linux the application you plan to deploy on Windows. It is Java after all :) – WhiteFang34 Mar 23 '11 at 05:47