标签:死锁
package test.thread;
public class DeadLockTest extends Thread{
private Object o;
public void setO(Object o){
this.o=o;
}
public void run(){
synchronized(this){
System.out.println("DeadLockTest begin");
synchronized(o){
System.out.println("DeadLockTest_o");
}
System.out.println("DeadLockTest end");
}
}
public static void main(String[] args) {
DeadLockTest dlt=new DeadLockTest();
TT tt=new TT(dlt);
dlt.setO(tt);
dlt.start();
tt.start();
}
}
class TT extends Thread{
private Object o;
public TT(Object o){
this.o=o;
}
public void run(){
synchronized(this){
System.out.println("TT begin");
synchronized(o){
System.out.println("TT_o");
}
System.out.println("TT end");
}
}
}
运行结果:多运行几次就会出现死锁现象
非死锁输出结果可能是:
DeadLockTest begin
DeadLockTest_o
DeadLockTest end
TT begin
TT_o
TT end
死锁结果:
eclise控制台:
eclipse debug窗口:
java VisualVm线程窗口:
java VisualVM线程Dump:
标签:死锁
原文地址:http://blog.csdn.net/zhangheliang2010/article/details/44837673