Constructor synchronization in Java

前端 未结 6 1111
执笔经年
执笔经年 2020-11-28 09:17

Someone somewhere told me that Java constructors are synchronized so that it can\'t be accessed concurrently during construction, and I was wondering: if I have a constructo

6条回答
  •  甜味超标
    2020-11-28 09:51

    Although this question is answered but the code pasted in question doesn't follow safe construction techniques as it allows this reference to escape from constructor , I would like to share a beautiful explanation presented by Brian Goetz in the article: "Java theory and practice: Safe construction techniques" at the IBM developerWorks website.

提交回复
热议问题