[concurrency-interest] safe publication ("initializing an object from static initializer")

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Jun 17 03:44:06 EDT 2013

On 06/07/2013 05:17 PM, Andy Nuss wrote:
> The quote from JCIP section 3.5.3, "initializing an object from static
> initializer", has me wondering in terms of non-64 bit static, but
> non-final, scalar and object variables initialized in an initializer
> directly, or indirectly thru a static function called by the initializer
> that sets such variable, what are the rules for publishing the change
> safely to other cores?

Makes no difference whether you are calling other methods from the
static initializer or not.

> Are all changes to static variables published at the end of the static
> initialization of the class?  What does hotspot do, and what exactly
> does this JCIP reference mean?

See the initialization rules in JVM spec:

All the fields initialized in the static initializers should be visible
to any user of that class. In other words, if the code observes the
initialized class, then it observes it's static state completely.


More information about the Concurrency-interest mailing list