Linux平台 jstack工具只对JDK6及以上有效,用jstack分析JDK5程序时报:"The VM does not support the attach mechanism"错误;
C:\Users\chad> jps 1308 DeadLock 4780 Jps
C:\Users\chad> F:\Software\jdk1.6.0_27\bin\jstack.exe 1308 2012-05-19 14:45:29 Full thread dump Java HotSpot(TM) Client VM (20.2-b06 mixed mode):
...
Found one Java-level deadlock :
"Thread-1": waiting to lock monitor 0x01adee04 (object 0x03c002d8, a deadlockEx.DeadLock\(Friend), which is held by "Thread-0" "Thread-0": waiting to lock monitor 0x01ae0664 (object 0x03c002e8, a deadlockEx.DeadLock\)Friend), which is held by "Thread-1" ... Found 1 deadlock.
测试样例(来自 Deadlock on Java docs ): package deadlockEx; public class DeadLock { static class Friend { private final String name; public Friend(String name) { this.name = name; } public String getName() { return this.name; } public synchronized void bow(Friend bower) { System.out.format("%s: %s" + " has bowed to me!%n", this.name, bower.getName()); bower.bowBack(this); } public synchronized void bowBack(Friend bower) { System.out.format("%s: %s" + " has bowed back to me!%n", this.name, bower.getName()); } } public static void main(String[] args) { final Friend alphonse = new Friend("Alphonse"); final Friend gaston = new Friend("Gaston"); new Thread(new Runnable() { public void run() { alphonse.bow(gaston); } }).start(); new Thread(new Runnable() { public void run() { gaston.bow(alphonse); } }).start(); } } HP-UX平台
用gcore