search

Home  >  Q&A  >  body text

java - synchronized修饰代码块括号后面锁失效?

PHPzPHPz2892 days ago424

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:31:25

    You can refer to my blog

    The use of Synchronized for thread synchronization

    Thread synchronization: Application of Synchronized in singleton mode

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:31:25

    This blog has the answer. However, the reference to global lock is easily misleading. Because sychoronized 是使用括号里的对象来上锁,而 String.class is not all instances of the String class, but an object, an object of type Class. Therefore, if you use different such class objects to synchronize, you will obtain different locks.

    reply
    0
  • Cancelreply