• 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:

Thread locks

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is from RHE;
How many locks does an object have?
1.
But every object can have class level lock and instance
lock.So, doesnt it make 2 locks.
Correct me where i am wrong?
2)A monitor is an instance of any class that has synchronized code. True/fals
This is true for instance methods.But
for class locks the monitor need not be
instance of any class.
Thanks!

[This message has been edited by avn (edited August 25, 2000).]
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
avn,
It is recommended that you post all thread and synchronization questions in the Threads forum.
To answer your question let us define an Object. An Object is an instance of a Class. Thus the Class and its Object are two different entities. The question specifically asked is how many locks does an Object have and since each instance of Object and its subclasses possesses a lock, there is only one lock associated per Object.
However there is also another lock, the Class Lock. The class lock is not associated with a Object but on the Class.
Note:
What object does non-static synchronized methods use for locking?
Non-static synchronized methods synchronize on the instance (this) of the class.
What object does static synchronized methods use for locking?
Static synchronized methods synchronize on the class object (this.getClass()) of the class.

------------------
Regds.
Rahul P. Mahindrakar
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am moving this to Threads Forum
Ajith
 
Screaming fools! It's nothing more than a 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