This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronized block parameter question  RSS feed

 
Richard Teston
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the synchronize block syntax:
synchronized( ? )
{
// code to be synchronized
}
What is the "?".?
What is its significance to the block?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ? is the object lock. Short answer is that it is an indication of something (an object) that must be unique for the threads to be able to get past.
If you use 'this', then that code block will only be able to be accessed by one thread on that instance at a time. If you use 'this.getClass()', the block will only be able to be executed by one thread at a time for all instances of that object type...
I recommend doing a search in this forum for 'Object Lock", but a nice thread is here
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little more complicated, but this one is nice too.
Dave
 
andyverma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard Teston:
In the synchronize block syntax:
synchronized( ? )
{
// code to be synchronized
}
What is the "?".?
What is its significance to the block?

? is the object refernce,the monitor of this object refence has to be acquired by the thread who wishes to exceute the block of synchronized code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!