safe publication and the advantage of being immutable vs. effectively immutable

后端 未结 4 1714
走了就别回头了
走了就别回头了 2020-12-08 20:50

I\'m re-reading Java Concurrency In Practice, and I\'m not sure I fully understand the chapter about immutability and safe publication.

What the book says is:

<
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 21:10

    I had the exact same question as the original poster when finishing reading chapters 1-3 . I think the authors could have done a better job elaborating on this a bit more.

    I think the difference lies therein that the internal state of effectively immutable objects can be observed to be in an inconsistent state when they are not safely published whereas the internal state of immutable objects can never be observed to be in an inconsistent state.

    However I do think the reference to an immutable object can be observed to be out of date / stale if the reference is not safely published.

提交回复
热议问题