package deadlock;
public class DeadLock {
public static void main(String[] args) {
MyDeadLock mdl1=new MyDeadLock(true);
MyDeadLock mdl2=new MyDeadLock(false);
mdl1.start();
mdl2.start();
}
}
package deadlock;
public class Lock {
public static final Object objA=new Object();
public static final Object objB=new Object();
}
package deadlock;
public class MyDeadLock extends Thread {
private boolean flag;
public MyDeadLock(boolean flag){
this.flag=flag;
}
public void run() {
if(flag){
synchronized(Lock.objA){
System.out.println("true****objA");
synchronized(Lock.objB){
System.out.println("ture***objB");
}
}
}else{
synchronized(Lock.objB){
System.out.println("false***objB");
synchronized(Lock.objA){
System.out.println("false***objA");
}
}
}
}
}
|
|