This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What is guaranteed with join()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What is guaranteed with join()?" Watch "What is guaranteed with join()?" New topic

What is guaranteed with join()?

E McKenney

Joined: Sep 01, 2006
Posts: 18

I believe I understand how join() normally works: Basically when the calling thread A calls B.join(), it goes into the waiting state until thread B ends, after which thread A becomes runnable again. However, I'm looking for clarification on what happens if join() is called after thread B is already dead (assuming the thread object still exists).

In practice, I imagine that thread A will appear to continue running, since the condition for continuing (i.e. thread B exiting) has already been satisfied. However I'm not sure whether thread A does stop executing briefly (for the few clock cycles necessary for the scheduler to make it runnable again), or if join() basically becomes a no-op when its thread is dead and thus thread A simply continues in the running state.

So, to use the SCJP exam terminology, would you say that the call to join() is "guaranteed to cause the calling thread to stop executing", even given a pathological (but not impossible) case like this? If I see such a statement on the exam, should I consider it to be true or false?


SCJP '06
Henry Wong

Joined: Sep 28, 2004
Posts: 20538

The join() method only waits if the thread is still alive. Calling it on a thread that has already completed should not block.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: What is guaranteed with join()?
It's not a secret anymore!