Double checked locking Article

后端 未结 10 656
别那么骄傲
别那么骄傲 2020-12-09 20:06

I was reading this article about \"Double-Checked locking\" and out of the main topic of the article I was wondering why at some point of the article the author uses the nex

10条回答
  •  自闭症患者
    2020-12-09 20:43

    Regarding this idiom there is a very advisable and clarifying article:

    http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html?page=1

    On the other hand, I think what dhighwayman.myopenid means is why the writer has put one synchronized block referring to the same class (synchronized(Singleton.class)) within another synchronized block referring to the same class. It may happen as a new instance (Singleton inst = instance;) is created within that block and to guarantee it to be thread-safe it's necessary to write another synchronized.

    Otherwise, I can't see any sense.

提交回复
热议问题