package ForkBlur;
public class DeadLockTest {
public static void main(String args[]) {
final DeadLockTest t1 = new DeadLockTest();
final DeadLockTest t2 = new DeadLockTest();
Runnable r1 = new Runnable() {
@Override
public void run() {
try {
synchronized (t1) {
System.out
.println("r1 has locked t1, now going to sleep");
Thread.sleep(100);
System.out
.println("r1 has awake , now going to aquire lock for t2");
synchronized (t2) {
Thread.sleep(100);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
try {
synchronized (t2) {
System.out
.println("r2 has aquire the lock of t2 now going to sleep");
Thread.sleep(100);
System.out
.println("r2 is awake , now going to aquire the lock from t1");
synchronized (t1) {
Thread.sleep(100);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
new Thread(r1).start();
new Thread(r2).start();
}
}