David said:
Thanks. I pronounced it broken too during the interview. However, I don't
have enough knowledge of the JMM to define exactly why.
The reason is that the Java memory model allows the target
field "_instance" to receive the reference to the newly
created instance *before* the instance has been fully
constructed. All threads that look at the field "_instance"
must be synchronized *before* peeking at the field. The
issue can be ameliorated somewhat by declaring the field
as "volatile", but that still violates the memory model
specification, even though it may work on most modern
hardware platforms.
For now, just bite the bullet and synchronize the access.
If the field is truly a singleton, then each thread can
save a copy of the value elsewhere for quicker local
access.