I'm reading B. Goetz Java Concurrency In practice and now I'm at the section 3.5 about safe publication. He stated:
// Unsafe publication
public Holder holder;
public void initialize() {
holder = new Holder(42);
}
This improper publication could allow another thread to observe a partially constructed object.
I don't see why it is possible to observe a partially constructed subobject. Assume, that the constructor Holder(int) does not allow this to escape. So, the constructed reference can be observed only by the caller. Now, as JLS 17.7 stated:
Writes to and reads of references are always atomic, regardless of whether they are implemented as 32-bit or 64-bit values.
it is impossible for thread to observe a partially constructed object.
Where was I wrong?