Effectively Immutable Object

后端 未结 3 1814
眼角桃花
眼角桃花 2021-01-31 22:09

I want to make sure that I correctly understand the \'Effectively Immutable Objects\' behavior according to Java Memory Model.

Let\'s say we have a mutable class which

3条回答
  •  再見小時候
    2021-01-31 23:12

    Yes. The write operations on the MutableLong are followed by a happens-before relationship (on the volatile) before the read.

    (It is possible that a thread reads Outworld.published and passes it on to another thread unsafely. In theory, that could see earlier state. In practice, I don't see it happening.)

提交回复
热议问题