Java 6 on Windows now supports the <jstack> utility as a mean to print stack traces (instead of relying solely on CTRL+BREAK).
Quick demo follows.
1) Write a program which is (pretty much) guaranteed to deadlock
public class Deadlock {
public static void main (String args[]){
final Object objA = new Object();
final Object objB = new Object();
new Thread() {
public void run (){
while (1==1) {
System.out.println ("Thread A synchronizing on objA");
synchronized (objA){
System.out.println ("Thread A synchronized on objA");
System.out.println ("Thread A synchronizing on objB");
synchronized (objB){
System.out.println ("Thread A synchronized on objB");
}
}
}
}
}.start();
new Thread() {
public void run (){
while (1==1) {
System.out.println ("Thread B synchronizing on objB");
synchronized (objB){
System.out.println ("Thread B synchronized on objB");
System.out.println ("Thread B synchronizing on objA");
synchronized (objA){
System.out.println ("Thread B synchronized on objA");
}
}
}
}
}.start();
}
}
2) Run the Deadock program
3) Get the deadlocked process id
4) Run jstack -> 1 deadlock detected.



[...] deadlocks with Reentrantlock Filed under: java — edgblog @ 12:17 pm This post showed how multiple threads synchronizing on two resources in different order usually leads to a [...]
Pingback by Avoiding deadlocks with Reentrantlock « Edgblog — February 16, 2008 @ 12:17 pm |
Somehow i missed the point. Probably lost in translation
Anyway … nice blog to visit.
cheers, Notoriety.
Comment by Notoriety — June 19, 2008 @ 7:34 am |
Wow enjoyed reading your article. I added your rss to my blogreader!!
Comment by AlielfVoive — December 11, 2009 @ 8:34 pm |
Guy .. Excellent .. Wonderful .. I’ll bookmark your website and take the feeds alsoI’m happy to seek out numerous helpful info right here within the publish, we’d like develop more strategies on this regard, thanks for sharing. . . . . .
Comment by Hindagringe — September 22, 2011 @ 10:48 am |