This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
synchronize a static method
Posted by raghuramrao on July 26, 2000 at 12:20 AM
Hello Kishori Sharma,
Thanx a lot.
I like to know one thing!
Since Static objects are class objects...,
does a static method uses same memory place
for all the objects of that class ?.
If that is the case I presume that....
in the previous senario,
all the objects of that class should wait until the
lock is released by the current thread.Am I correct !?.
thanx in advance.
> a. Can we synchronize a static method
> Ans: Yes. You can synchronize a static method.
> b. if YES what is its effect in multi threading environment.
> Ans: If one thread is executing a static synchronized method of a class then it holds a lock on all other syncronized methods of that class and in effect no other thread can call any of the synchonized static methods of that class untill this current thread releases the lock.
> c. if NO why
> Ans: ---