简体   繁体   中英

Does a static method synchronization delay creation of object of the class?

class A{
    synchronized static void method(){
        doSomethingLongTime(); // here A.class monitior is taken.
    }
}

.......

new A(); // does this blocked by doSomethingLongTime() ?

The code above depicts my question: new A() definetly deal with A.class, so is it blocked?

Nope. The lock on the static method is acquired on A class object. That is right. But new A() is not inside synchronized block. So this line doesn't need to wait for any lock object & can proceed. Construction of new object won't be blocked otherwise explicitly specified within a synchronized block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM