Possible Duplicate:
How do synchronized static methods work in Java?
I was wondering what would happen if synchronized was used on a static method. Does the class get a lock on that method? How is this different from synchronized on a non static method?
Thanks
Yes, the class “gets” the lock instead of the instance (as Bruno pointed out, this terminology is imprecise. The Thread gets the lock using either the class object or the instance as the locking object). Meaning, you could have 3 threads simultaneously executing 3 synchronized methods if those methods are synchronized on their individual instances. If the method is synchronized on the class, then only one thread can be executing it.