Static initializers and safe publication
Ho开发者_JS百科w does initializing an object reference from a static initializer guarantee safe publication?
Using a static initializer is often the easiest and safest way to publish objects that can be statically constructed:
public static Holder holder = new Holder(42);
Static initializers are executed by the JVM at class initialization time; because of internal synchronization in the JVM, this mechanism is guaranteed to safely publish any objects initialized in this way [JLS 12.4.2].
精彩评论