[concurrency-interest] Static initializer

Bill Pugh pugh at cs.umd.edu
Tue Apr 10 16:02:23 EDT 2007

Actually, I don't think you need the final field semantics
to get thread safety in this case.

All threads that invoke MyClass.getInstance() are guaranteed
to be correctly ordered with respect to the initialization of
MyClass. Thus, they are ordered with respect to both the writing
of the static "instance" field and the instance field "map".

Making the fields is a good idea, but not required to get thread
safety (assuming you don't introduce data races anywhere else).


More information about the Concurrency-interest mailing list