Java Synchronized Block for .class
问题 What does this java code mean? Will it gain lock on all objects of MyClass ? synchronized(MyClass.class) { //is all objects of MyClass are thread-safe now ?? } And how the above code differs from this one: synchronized(this) { //is all objects of MyClass are thread-safe now ?? } 回答1: The snippet synchronized(X.class) uses the class instance as a monitor. As there is only one class instance (the object representing the class metadata at runtime) one thread can be in this block. With