What does static method synchronization do?

Possible duplicate:
How do synchronized static methods work in Java?

I was wondering what would happen if synchronization was used for the static method. Does the class get a lock on this method? How does this differ from non-stationary synchronization?

thanks

+6
java concurrency
source share
2 answers

Yes, the class "gets" the lock instead of the instance (as Bruno pointed out, this terminology is inaccurate). A theme gets a lock using either a class object or an instance as a lock object). So you could have 3 threads running 3 synchronized methods at the same time if these methods are synchronized in their separate instances. If the method is synchronized in the class, then only one thread can execute it.

-one
source share

This question contains many high-quality answers to the question above.

+4
source share

All Articles