Thread safety of static blocks in Java

前端 未结 4 1684
抹茶落季
抹茶落季 2020-11-28 12:20

Let\'s say I have some Java code:

public class SomeClass {
    static {
        private final double PI = 3.14;
        private final double SOME_CONSTANT =          


        
4条回答
  •  离开以前
    2020-11-28 12:56

    If the first thread hasn't finished initializing SomeClass, the second thread will block.

    This is detailed in the Java Language Specification in section 12.4.2.

提交回复
热议问题