The moose likes Threads and Synchronization and the fly likes Object Monitor Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Object Monitor Question" Watch "Object Monitor Question" New topic
Author

Object Monitor Question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Let's say that I have a single instance of an object, and several references to that object. If I create a synchronized block that synchronizes on one of the object references, is access to the object instance synchronized, or is access to only the reference synchronized?
...Mike Broadbear
Mike Broadbear
Ranch Hand

Joined: Jan 14, 2002
Posts: 39
Sorry for posting under 'broadbear'. Is there any way that account could be deleted?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
Done. As for your question - you're really synchronizing on the object, not the reference. Multiple references to the same object are treated equally - the first to attempt to acquire a lock will get it, and the rest will wait.


"I'm not back." - Bill Harding, Twister
 
 
subject: Object Monitor Question
 
Threads others viewed
Synchroniztaion question
thread q
Doubt in threads
Thread locks
can thread access the non-synchronized method in a class when other thread hold lock
developer file tools