I've just read some code, and notice there is some code with synchronized a local object. Could some one tell me what dose it mean when we do it since we just create a new local object, why should we lock it ?
list queue;
...
public send()
{
entry = waitEntry();
//add this object into the list
queue.add(entry);
...
synchronized( entry )
{
//do some sth
entry.wait();
}
}
then, when we receive the response, unlock this object
public receive()
{
entry = list.get() <-- get the object we have sent before
synchronized( entry )
{
entry.notify()
}
}
As you see, I already lock the 'entry' before, how can I locked it again in receive() method ?
Thanks everyone.