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
The question is: Does Java Memory Model guarantee that all threads MUST have Outworld.published.get() == 3 ?
The short answer is no
. Because other threads might access Outworld.published
before it has been read.
After the moment when Outworld.published = val;
had been performed, under condition that no other modifications done with the val
- yes - it always be 3
.
But if any thread performs val.increment
then its value might be different for other threads.