实例化如下定义的SynchroClass实例,并且当第二个sCMethod
试图锁定sCMethod
时,调用lockObject
会导致死锁吗?
SO暗示我的意思可能是Re-entrancy in Java saves us from a deadlock situation in this code sample.. How, why?,这似乎暗示它不是死锁,因为同一个对象已经具有锁拥有权,但是它涉及synchronized
方法,所以是至少有点不同。
class SynchroClass {
static Object lockObject = new Object();
private boolean otherCondition = true;
public boolean sCMethod(boolean condition) {
synchronized(lockObject) {
if(condition) {
// some code
} else if(otherCondition) {
// some code
sCMethod(false);
// some code
} else {
// some code
}
return true;
}
}
}