Reputation: 3886
i coundn't understand an simple question,
what does a synchronized method use as a mutex
in java-
a) A globally declared mutex
b) A method's mutex
c) A owning object's(this's) mutex
can anybody elaborate this? thanks in advance
Upvotes: 1
Views: 1817
Reputation: 16338
It’s option c); from Goetz et al. (2006), Java Concurrency in Practice:
A
synchronized
method is a shorthand for asynchronized
block that spans an entire method body, and whose lock is the object on which the method is being invoked. (Staticsynchronized
methods use theClass
object for the lock.)
Upvotes: 2