我正在尝试使用加入线程(JAVA)来创建死锁。根据我的理解,下面的程序应该终止。有人可以解释为什么下面的程序没有终止吗?
public class DeadLockUsingJoins2 {
public static void main(String[] args) {
AThread a = new AThread(null, "A");
a.start();
AThread b = new AThread(a, "B");
b.start();
a.t = b;
}
}
class AThread extends Thread{
public Thread t;
public AThread(Thread thread, String name){
super(name);
this.t = thread;
}
@Override
public void run(){
try {
if(t != null)
t.join();
else
{
Thread.sleep(5000);
}
// if(t != null)
// t.join();
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("Somebody interruped thread - " + this.getName());
}
System.out.println("Winding Up thread - " + this.getName());
}
}