...
The field flag
is not required to be volatile
because the initialization is being carried out in a static initializer and is guaranteed to finish before the object becomes usable.
Compliant Solution (static
initializer, no background threads)
This compliant solution also uses a static
initializer but does not spawn a background thread from it.
...