Reputation: 33
Suppose I have 2 methods, one declared as synchronized
and the other declared as static synchronized
.
So when a thread acquires the class-level lock, does it acquire the locks on all its instances as well? In other words, if a thread acquires a class-level lock, can another thread acquire an object-level lock on one of its instances simultaneously?
Upvotes: 1
Views: 168
Reputation: 51657
A static synchronized
method will acquire the lock on the Class
instance for the class. A synchronized
method will acquire the lock on this
. When you acquire the class level lock by calling a synchronized static method, the object-level locks are not affected.
Upvotes: 6