I am trying to create a deadlock using join in threads (JAVA). According to my understanding the below program should terminate. Can somebody please explain why the below program doesn't terminate?
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());
}
}