Reputation: 1090
Which locks are held in overridden non-static synchronized methods. Please provide the sequence in which the monitor locks of base-class and sub-class are acquired and released so that it explains the benefit of Reentrancy in java. It would be great if the sequences can be explained with the help of owning thread and acquisition count that JVM maintains to implement reentrancy.
public class Widget {
public synchronized void doSomething() {
}
}
public class LoggingWidget extends Widget {
public synchronized void doSomething() {
super.doSomething();
}
}
Please note that this question is specifically asked for the explanation of implicit reentrant locks, so pls dont mark it as a duplicate.
Upvotes: 1
Views: 561
Reputation: 692231
Each object has an associated monitor. When a synchronized instance method is called on an object, the monitor associated with this object needs to be held by the calling thread.
The class of the object is irrelevant.
Upvotes: 1