wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes join() mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "join() mock exam question" Watch "join() mock exam question" New topic
Author

join() mock exam question

Tamara Lopez
Ranch Hand

Joined: Feb 21, 2006
Posts: 63
From K&B mock exams

Assuming that an interrupted exception has not been thrown and that "aLiveThread" is a runnable thread, which three guarantee that a thread will leave the running state?

a) yield()
b) wait()
c) notify()
d) notifyAll()
e) sleep(1000)
f) aLiveThread.join()
g) Thread.killThread()


The correct answers are b e and f.
I dont understand why f is correct. is it not the thread that is calling that method that will leave the running state? In this case main will leave the running state and wait for aLiveThread to finish??
thanks
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
When you call wait() the running thread releases all locks and waits to be notified by another thread that a condition just happened. In this case, the running thread will block until the condition happens, and then running thread will temporarily abandon the running state.

In the second case, join() will assure that the currently running thread will block until the thread whose join method is called has finished its execution, in other words, when the run() method of the joined thread completes (whether normally o becauase of an exception).

In this case, the running thread will temporarily abandon the running state until the joined thread finishes.
Tamara Lopez
Ranch Hand

Joined: Feb 21, 2006
Posts: 63
oh the question reads "that A thread leaves the running state". I misread that - I thought it meant aLiveThread leaves the running state. In which case f wouldn't be correct.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: join() mock exam question