Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object's lock

 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a lock is obtained on an object instance no synchronized method can be executed by anyone but the owner of the lock. Is it true that when a lock is obtained the synchronized blocks of code will also be available to the owner only.
[ May 18, 2003: Message edited by: Anupam Sinha ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's the other way round: A thread becomes the owner of the object's monitor by executing that object's synchronized code.
 
Rattan Mann
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Often the only difference between synchronized method and synchronized code block is that you don't want to lock up the whole method but only that critical part of the method which needs synchronization. This improves performance.
Rat
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply Roger and Rattam. Rattam your answer helped me clear this doubt.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic