| Author |
Couple of Thread Qs from JQPlus
|
Himanshu Jhamb
Ranch Hand
Joined: Aug 01, 2001
Posts: 134
|
|
Hi Ranchers. These are just some snippets from a couple of JQ+ thread Qs. Q1) When a thread calls notify() from within its synchronized block, does it say to the waiting threads that "Hey! Guys, I am relinquishing the lock on this object." & actually does so ? Q2) Can a join operation on a thread cause some other thread to stop? Thanks - Himanshu
|
Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
A1) No. Unlike wait(), which blocks immediately and gives up its lock, notify() and notifyAll() won't actually give up the lock on the object until execution exits the synchronized block in which the notify()/notifyAll() is located. Example: ... synchronized(this){ //do stuff notify(); //thread not block, nor locks surrendered //do more stuff } //end of synchronized block, thread gives up locks A2) Yes. Calling join() on thread A causes the current thread to be suspended until thread A completes, at which time the thread that invoked join() will continue.
|
Rob
SCJP 1.4
|
 |
Muhammad Usman
Greenhorn
Joined: Nov 18, 2001
Posts: 29
|
|
|
there are other version of the join(), which waits for milli seconds, for a thread to complete, then starts whether or not calling thread has got its execution complete or not.
|
an student of Operation Badar ( a educational movement in Pakistan).
|
 |
 |
|
|
subject: Couple of Thread Qs from JQPlus
|
|
|