标签:shu lock ofo 一个 rri lag object zed override
/***/
public class Demo {
public static void main(String[] args) {
Test t = new Test(true);
Thread rr=new Thread(t);
rr.start();
Test t1 = new Test(false);
Thread rr1=new Thread(t1);
rr1.start();
}
}
class MyLock{
public static Object lockA = new Object();
public static Object lockB = new Object();
}
class Test implements Runnable{
private boolean flag;
public Test( boolean flag){br/>this.flag=flag;
}
@Override
public void run() {
if(flag){
synchronized (MyLock.lockA) {
System.out.println("if lockA");
synchronized (MyLock.lockB) {
System.out.println("if lockB");
}
}
}else{
synchronized (MyLock.lockB) {
System.out.println("else lockB");
synchronized (MyLock.lockA) {
System.out.println("else lockA");
}
}
}
}
}
标签:shu lock ofo 一个 rri lag object zed override
原文地址:http://blog.51cto.com/13579086/2065319