What's the use of having a synchronized static method?
Joined: Feb 23, 2006
I undesrtand that the use of having a synchronized method is, no 2 threads will try to execute one method at a time and corrupt the state of an object. So synchronized is useful when it come to instance methods. But what's the use of having a synchronized static method? Thanks JEAN.
It's the same reason. Why do you think there is a difference? Threads can execute static methods just as easily as instance methods.
Joined: Jul 11, 2001
Synchronizing static methods is useful when the method accesses a shared "static" resource, such as a static field, an external resource etc.
A static method synchronizes on the Class object of the class it is declared on (instead of "this").
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus