Rahul Rabhadiya
Rahul Rabhadiya

Reputation: 430

If I make class level lock on static method & if one thread execute it so will it block other thread executing other instance method of same class?

Suppose we have one class in which we have one instance method and static method. We have synchronized block in static method with class level lock & we have synchronized block in instance method with object level lock. So suppose when one thread start executing static method and make class level lock , at the same time another thread try to execute instance method. So will that second thread will be blocked from execution of instance method ??

Upvotes: 0

Views: 137

Answers (2)

handsp
handsp

Reputation: 127

the second thread will not be blocked。the class level lock & this class Object level lock,the two locks are different, but they can be re-entered each other

Upvotes: 1

Snehal Patel
Snehal Patel

Reputation: 1330

It’s possible that both static synchronized and non static synchronized method can run simultaneously or concurrently because they lock on different object.

Upvotes: 0

Related Questions