• 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

Synchronization and Locks

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Kathy & Bert Java 5 book, it states that each object has just one lock (page 707). What does this mean?

I am confused because the book continues saying that (page 709)

That gives you the ability to have more than one lock for code synchronization within a single object.



Help? Thank you.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I think the meaning is when you have multiple object which are accessing the same shared rsources but if the block is in synchronized then only one object is eligible for access.

Please coorect me if i am wrong.

Thanks
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It�s like this

Think there is a room with a pad-lock. If you enter that room then u will lock that room so no one else can enter into there. Once you have released only, any other can get in.

The same applies to threads too.
Room is an Object... Pad-lock is the lock� and you and others are threads.
 
Buhi Mume
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The room and padlock analogy explains that an object has one lock. But how about the following?

That gives you the ability to have more than one lock for code synchronization within a single object.

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Buhi, the statements appear to be contradictory. I am confused as well.
reply
    Bookmark Topic Watch Topic
  • New Topic