public void run() {
if(flag) {
lock1.lock();//加锁
System.out.println("if objA");
lock2.lock();
System.out.println("if objB");
lock2.unlock();
lock1.unlock();
}else {
lock2.lock();
System.out.println("else objB");
lock1.lock();
System.out.println("else objA");
lock1.unlock();
lock2.unlock();
}
} |
|