synchronized

What will happen to a static synchronized method?
Since static method is associated with a class, not an object.
So thread acquires intrinsic lock for the Class object associated with the class.

Access to class's static fields is controlled by a lock that is distinct from the lock for any instance of the class. -- by Java doc.

In a word, static fields in a class own a different lock from the instance of class.

你可能感兴趣的:(synchronized)