在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java  Linux/ 用內(nèi)部成員實(shí)例做lock,而不用實(shí)例自身this做同步有何好處?

用內(nèi)部成員實(shí)例做lock,而不用實(shí)例自身this做同步有何好處?

譬如Writer定義就用一個(gè)lock,

public abstract class Writer implements Appendable, Closeable, Flushable {

  /**
   * The object used to synchronize operations on this stream.  For
   * efficiency, a character-stream object may use an object other than
   * itself to protect critical sections.  A subclass should therefore use
   * the object in this field rather than <tt>this</tt> or a synchronized
   * method.
   */
  protected Object lock;
  。。。
  }

看了英文解釋?zhuān)f(shuō)是有利于子類(lèi),但是具體好處沒(méi)說(shuō)清楚。

回答
編輯回答
笑浮塵

哪里提到內(nèi)部類(lèi)了???
無(wú)參構(gòu)造器不是賦值this嗎?

    protected Writer() {
        this.lock = this;
    }
2018年1月31日 12:26
編輯回答
黑與白

解耦吧。用戶(hù)可以傳自己的lock 進(jìn)去

2018年3月20日 08:26