在深入研究Java并发性的同时,我在 Java Concurrency in practice
中找到了一个Reenterant锁定机制的示例public class Widget {
public synchronized void doSomething() {
...
}
}
public class LoggingWidget extends Widget {
public synchronized void doSomething() {
System.out.println(toString() + ": calling doSomething");
super.doSomething(); // which object is locked this or super
}
}
调用方法LoggingWidget.doSomething()
LoggingWidget 对象的锁定由线程获取。此方法还在方法中调用super.doSomething()
。调用super.doSomething()
,Widget
或LoggingWidget
?