I guess this is some kind of term paper. It seems that in this particular problem it is worth highlighting the two fundamental foundations of Java
- Any object can serve as a monitor in Java
- How
synchronized implicitly uses the current instance of an object as lock
Paragraph 1 talks a lot about understanding what a monitor is. I invite you to study the relevant section of the Java language specification, Threads and Locks . A monitor is what a thread can lock and unlock . When one thread blocks it, any other thread trying to block this particular monitor will wait (block) until the first thread unlocks it.
Point 2 is dedicated to the compiler function in Java. When you specify something as synchronized , without explicitly specifying which monitor to use, Java will use the instance of the called object. If, however, the method is static, it will use an instance of class objects ( java.lang.Class ) as a monitor. What does this really mean? Since there is only one unique global instance of each class object in the context of the loader class, the static method will have only one monitor. In contrast, an instance method will use an instance of an object that is called as a monitor, so each object will have its own monitor. Static methods are synchronized globally, the instance method is synchronized for each specific instance of the class.
source share