0

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 ??

Rahul Rabhadiya
  • 430
  • 5
  • 19
  • Is this one lock object, two lock objects or how is locked. Please read st [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and show code examples. – P.J.Meisch Apr 26 '17 at 06:54

2 Answers2

1

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

handsp
  • 127
  • 5
0

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

Snehal Patel
  • 1,282
  • 2
  • 11
  • 25
  • two non static synchronized method can also run simultaneously given the lock on two different object. Static synchronized means I am locking at class level e.g synchronized (A.class) .so at that time entire class get locked ?? so even other thread can not execute any instance method ?? – Rahul Rabhadiya Apr 26 '17 at 07:09