J.J. Beam
J.J. Beam

Reputation: 3059

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?

Upvotes: 0

Views: 96

Answers (1)

aatwork
aatwork

Reputation: 2270

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.

Upvotes: 1

Related Questions