开发者

Static initializers and safe publication

开发者 https://www.devze.com 2023-01-29 11:24 出处:网络
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 b

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].

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号