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
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.
Joined: Feb 21, 2006
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.