This week's book giveaway is in the Spring forum.
We're giving away four copies of Java Persistence with Spring Data and Hibernate and have Cătălin Tudose on-line!
See this thread for details.
Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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.

 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic