• 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

class lock

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ranchies,
can anybody plz explain me, what is class lock?...how it is different from object lock......

i read that when we make instance method synchronized then by calling to this method we get the object lock and no other object have acces to other synchronized method.....

So my question is what happens when we call static synchronized method.....?

i read that we get the class lock...so what is that actually...?

Regards
Hrushi
:roll:
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no such thing as a "class lock". All locks are on object instances.
What happens when you call a synchronized static method of a class? When the class gets loaded, an object of the class Class is created. A lock is obtained on this (disregarding classloader issues) unique Class object.

You could, I suppose, refer to the above mentioned lock as the "class lock", but is really a normal lock on an object.
[ November 15, 2005: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want it from the JLS, Section 8.4.3.6 states:

For a class (static) method, the monitor associated with the Class object for the method's class is used.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic