So, the following is
thread safe due to immutability:
And the following is safe due to synchronization:
Now consider the following class:
Two questions:
1. Is this thread safe?
2. Can someone point to the relevant part of the
Java Language Specification?
The reason I ask is that I can only find comments about "final" ensuring thread safety in the context of immutable objects, by ensuring a store barrier before exiting the constructor. Is such a barrier ensured even if only some of the member data is final? Does the barrier come at the end of the constructor, or might it occur before the initialization of nonfinal members?
(Edited to remove an unintended "synchronized" before the accessor of the final variable in the Mixed class.)
[ October 22, 2008: Message edited by: Warren Dew ]