wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Object's lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Object Watch "Object New topic
Author

Object's lock

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Rattan Mann
Ranch Hand

Joined: Jan 21, 2003
Posts: 44
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

Joined: Apr 13, 2003
Posts: 1088
Thanks a lot for the reply Roger and Rattam. Rattam your answer helped me clear this doubt.
Thanks
 
 
subject: Object's lock
 
Similar Threads
Class Wide Lock..??
Whose lock will be obtained
Threads-Can someone reply to this que?
can we Do Calss Level Locking
Synchronised method