This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Object Monitor Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
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: 18670
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Object Monitor Question
 
Similar Threads
thread q
Synchroniztaion question
Doubt in threads
Thread locks
can thread access the non-synchronized method in a class when other thread hold lock