public class TestDeadLock{
static Object O1 = new Object ();
static Object O2 = new Object ();
public static void main(String args[]){
Runner6 T1 = new Runner6();
Runner6 T2 = new Runner6();
T1.flag = false;
T1.start();
T2.start();
}
}
class Runner6 extends Thread{
public boolean flag = true;
public void run(){
if(flag){
synchronized(TestDeadLock.O1){
System.out.println("O1锁住了");
try{sleep(1000);}catch(InterruptedException e){}
}
synchronized(TestDeadLock.O2){
System.out.println("2");
}
}
else{
synchronized(TestDeadLock.O2){
System.out.println("O2锁住了");
try{sleep(1000);}catch(InterruptedException e){ }
}
synchronized(TestDeadLock.O1){
System.out.println("1");
}
}
}
}
繁星点点滴滴
眼眸繁星