Consider this synchronized example. The same applies to lock but with more code.
synchronized int getSum() {
return getValue() + getOtherValue();
}
synchronized int getValue() {
return value;
}
synchronized int getOtherValue() {
return value;
}
The only way to avoid being re-entrant is to create locked and unlocked versions of each method. However what if you have two instances A and B. A calls B which calls A. How does B know not to call a synchronized method in A.