package day23;
public class DeadLockTest1 {
public static void main(String[] args) {
DeadLock d1 = new DeadLock(true);
DeadLock d2 = new DeadLock(false);
d1.start();
d2.start();
}
}
class DeadLock extends Thread {
public boolean flag;
public DeadLock(boolean flag) {
this.flag = flag;
}
@Override
public void run() {
if (flag) {
synchronized (MyLock.objA) {
System.out.println("A-true");
synchronized (MyLock.objB) {
System.out.println("B-true");
}
}
} else {
synchronized (MyLock.objB) {
System.out.println("A-false");
synchronized (MyLock.objA) {
System.out.println("B-false");
}
}
}
}
}
class MyLock {
public static final Object objA = new Object();
public static final Object objB = new Object();
}
|