Saket Mittal
Saket Mittal

Reputation: 3886

synchronized method use as a mutex in java

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

Answers (1)

Chriki
Chriki

Reputation: 16338

It’s option c); from Goetz et al. (2006), Java Concurrency in Practice:

A synchronized method is a shorthand for a synchronized block that spans an entire method body, and whose lock is the object on which the method is being invoked. (Static synchronized methods use the Class object for the lock.)

Upvotes: 2

Related Questions