Depending on exactly what data you need, you can just get this information from within your Java program. For example, something like this will sample held locks 20 times a second for 100 seconds, creating effectively a map of lock > approximate time locked (number of "ticks" during which the given lock was being locked on):
private static void runProfile() {
try {
final int noSeconds = 100;
final int sleepMillis = 50;
final int noSamples = noSeconds * 1000 / sleepMillis;
ThreadMXBean thb = ManagementFactory.getThreadMXBean();
Map<String,Integer> blockCounts = new HashMap<String, Integer>(50);
for (int i = 0; i < noSamples ; i++) {
long[] ids = thb.getAllThreadIds();
ThreadInfo[] infs = thb.getThreadInfo(ids, 0);
for (ThreadInfo ti : infs) {
LockInfo lockInf = ti.getLockInfo();
if (lockInf != null) {
String key = lockInf.toString();
Integer cnt = blockCounts.get(key);
blockCounts.put(key, cnt == null ? 1 : cnt+1);
}
}
Thread.sleep(sleepMillis);
}
System.out.println("Locks:");
for (String lockName : blockCounts.keySet()) {
System.out.println(lockName + " : " + blockCounts.get(lockName));
}
} catch (InterruptedException iex) {
Thread.currentThread().interrupt();
}
}
Adapt to collect the data as you need it.
You can then start this going in a background thread e.g.:
Thread thr = new Thread() {
public void run() {
runProfile();
}
};
thr.setPriority(Thread.MAX_PRIORITY-1);
thr.start();