How is monitor acquired in case of static function?
According to JLS Section §8.4.3.6:
A synchronized method acquires a monitor (§17.1) before it executes.
For a class (static) method, the monitor associated with the Class object
for the method's class is used.
In this synchronized method move class level lock is acquired. So which
Class object is exactly used for obtaining this lock. Is it
Interface.class or ClassImplementingInterface.class? If it is the later is
there any scenario where we can have interface monitors? or rather does
interface have a monitor?
I have read each object is associated with a monitor and in case of static
locks monitor is obtained on corresponding Class object. As we can do
Interface.Class which means interface has corresponding Class object can
we get a lock on that monitor without explicitly saying
synchronized(Interface.class).
No comments:
Post a Comment