This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization and Locks

 
Buhi Mume
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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.
 
Sujittt Tripathyrr
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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
 
Poobhathy Kannan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Tony Shivpershad
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Buhi, the statements appear to be contradictory. I am confused as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic