This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What is guaranteed with join()?" Watch "What is guaranteed with join()?" New topic
Author

What is guaranteed with join()?

E McKenney
Greenhorn

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?

Thanks,
b.


SCJP '06
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18508
    
  40

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

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is guaranteed with join()?
 
Similar Threads
methods which stop a thread?
Thread
Note on Thread
Threads Notes for Exams
A question of Thread from Sun's Assessement test