• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

synchronized

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one help me with this question?
When synchronozed is used as a modifier to a static method, what would be the monitor?
Thanks
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static synchronized block would lock the entire Class.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
George Toronto
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic