Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Couple of Thread Qs from JQPlus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Couple of Thread Qs from JQPlus" Watch "Couple of Thread Qs from JQPlus" New topic

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?
- Himanshu

Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Rob Ross

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.
//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.

SCJP 1.4
Muhammad Usman

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).
I agree. Here's the link:
subject: Couple of Thread Qs from JQPlus
It's not a secret anymore!