Static synchronized block would lock the entire Class. Could you explain it more? static members belong to the entire class. my teacher told me the mechanism about static member is different with the lock mechanism of sychronization, monitor so called. but he didnot claim the reason, so in my mind monitor maybe is not the mechanism of static. Moreover, i am sure the entire class is locked when static sychronized method are called. i hope you can explain it more deep and detailly. Thanks George
Joined: Dec 30, 2000
Originally posted by Ajith Kallambella: Static synchronized block would lock the entire Class.
i check the khalid's book, and the following is my understanding: as i said before, i think the monitor of static synchronied method is different from the monitor of general sychronized method. the former is " a class-sepcific monitor" (quoted from the book); the later is just the object monitor. Plz attention one is CLASS monitor, anther is OBJECT one. a thread acquires the class monitor before it can process with the excution of any static sychronized method in the class, blocking other threads wishing to excute any <red>such methods</red> in the same <red>class</red>. moreover, the thread with static sychronized method doesnot effect the performance of the other threads acquiring the monitor on any object of the class to excute the only <red>sychronized</red> non-static methods. the class monitor and object monitor are , after all, independent each other. that is clear? if not, plz refer to khalid's book. teh explaination is cool and like oracle(not database,just english word)! regds George
Of course they are different. But this difference is only because they are different objects! As you are aware every object is a resource which acts as a lock having a key. Obviously, every object of a class is an independent lock. In case of non-static methods the object is the same object on which the method is called. In the case static methods, the object is the class object. For every java class that is loaded by the JVM, an object of class 'java.lang.Class' is created. And this is the object which acts as the lock for static methods of that class. HTH, Paul. ------------------ Get Certified, Guaranteed! (Now Revised for the new Pattern) www.enthuware.com/jqplus