为什么“都会在处理前获得Widget”的锁?

解决方案 »

  1.   

    那个“Widget的锁”其实指的是LoggingWidget对象上的锁
      

  2.   

    http://ifeve.com/locks/#lockReentrancehttp://ifeve.com/reentrance-lockout/http://ifeve.com/read-write-locks/#reentrance
      

  3.   

    英文的原话是:
    Because the doSomething methods in Widget and LoggingWidget are both synchronized, each tries to acquire the lock on the Widget before proceeding. 我咋感觉应该是lock on the LoggingWidget 而不是Widget呢?
      

  4.   


    锁对象确实是LoggingWidget,也许这里原文是个笔误,也许是用父类引用泛指子类对象这样来描述的
    《Java Concurrency in Practise》的这一处确实给不少人带来了疑惑。