Henry Wong wrote:
It may be a good idea to tell us what you are confused with. Or maybe tell us what you do understand. At this point, there is not enough clarity to give you a quick answer -- besides pointing you parts of the Oracle tutorial on threads.
Henry
Hi l meant that in K&B book "
Thread Interaction" part .Book explains this topic with a simple example.Which is just below.
and than adding this part which confused my mind
When the thread waits, it temporarily releases the lock for other threads to use, but
it will need it again to continue execution. It's common to find code like this:
synchronized(anotherObject) { // this has the lock on anotherObject
try {
anotherObject.wait();
// the thread releases the lock and waits
// To continue, the thread needs the lock,
// so it may be blocked until it gets it.
} catch(InterruptedException e){}
}
The point that book tells "
When the thread waits, it temporarily releases the lock for other threads to use, but it will need it again to continue execution" made my mind confused.
Let me explain you what l understand from this sentence(
When the thread waits, it temporarily releases the lock for other threads to use, but it will need it again to continue execution)
Check me whether l am right.
This sentence want to express that ;
The
thread which is waiting between synchronized blocks for notification (in this case other threads can not enter this synchronized block ) it temporarily releases the lock without ending
its job in the synchronized block.
we already know that any thread in the synchronized block will not release the lock until they finish own job in the synchronized code. is not it?
Thaks for your answers