Sail E0 Webinar
Question

Which three guarantee that a thread will leave the running state?

     1. yield()

     2. wait()

     3. notify()

     4. notifyAll()

     5. sleep(1000)

     6. aLiveThread.join()

     7. Thread.killThread()


Options:
A .  1, 2 and 4
B .  2, 5 and 6
C .  3, 4 and 7
D .  4, 5 and 7
Answer: Option B

(2) is correct because wait() always causes the current thread to go into the object's wait pool.

(5) is correct because sleep() will always pause the currently running thread for at least the 

duration specified in the sleep argument (unless an interrupted exception is thrown).

(6) is correct because, assuming that the thread you're calling join() on is alive, the thread calling

 join() will immediately block until the thread you're calling join() on is no longer alive.

(1) is wrong, but tempting. The yield() method is not guaranteed to cause a thread to leave the 

running state, although if there are runnable threads of the same priority as the currently running

 thread, then the current thread will probably leave the running state.

(3) and (4) are incorrect because they don't cause the thread invoking them to leave the running state.

(7) is wrong because there's no such method.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers