File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Synchronized block parameter question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Synchronized block parameter question" Watch "Synchronized block parameter question" New topic
Author

Synchronized block parameter question

Richard Teston
Ranch Hand

Joined: Feb 12, 2002
Posts: 89
In the synchronize block syntax:
synchronized( ? )
{
// code to be synchronized
}
What is the "?".?
What is its significance to the block?


The Code is the Programmer
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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


[ JavaRanch FAQ ][ Book Promotions ][ DbTamer ][ BumperStickers ][ JavaRanch Badges ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

A little more complicated, but this one is nice too.
Dave
andyverma
Greenhorn

Joined: Jun 14, 2002
Posts: 2
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.


Andy
 
 
subject: Synchronized block parameter question
 
Threads others viewed
Synchronized block and methods
synchronized
Synchroniztion
static synchronized block
sleep() inside Synchronized block
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com