• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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.

 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic