ReentrentLock对此对象或超级对象

时间:2016-12-28 06:22:55

标签: java multithreading java.util.concurrent

在深入研究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()WidgetLoggingWidget

时,哪个对象已被锁定

0 个答案:

没有答案