I got two qs : What might cause the current thread to stop executing.
A. An InterruptedException is thrown. B. The thread executes a wait() call. C. The thread constructs a new Thread. D. A thread of higher priority becomes ready. E. The thread executes a waitforID() call on a MediaTracker. What might cause the current thread to stop executing?
A. An InterruptedException is thrown B. The thread executes a sleep() call C. The thread constructs a new Thread D. A thread of higher priority becomes ready (runnable) E. The thread executes a read() call on an InputStream I need your idea to correct myself!!
Tian, What do you think the answers are? Think aloud and post your opinions along with the question, it helps others too! Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Joined: Jul 10, 2000
sorry I forgot to post mine. My idea is a b d e for both, what do you think?
Joined: Mar 17, 2000
A - Is debatable. InterruptedException doesn�t always stop a running thread. The thread could catch the exception and continue running. B - Yes. sleep(), wait() or join() stops the running thread. D. A thread of higher priority becomes ready C - No! D - Is debatable. Though this is usually true, it certainly depends on the implementation of the thread scheduler. For example, a time-slicing scheduler may not honor thread priorities. E - Yes. Thread is blocked by an operation and is waiting for something to happen( I/O block for eg). Here again, you will have to distinguish between "Waiting","Blocked" and "Stopped" states. I hope the questions in the real exam are far more clearer than this. Ajith
A - I think no. For an InterruptedException to be thrown, the thread must have already been waiting or sleeping, right? Then an interrupt() is invoked on the thread, and that acually restarts the execution of the thread. Of course, the execution takes the form of an exception being thrown - but that doesn't stop execution itself. Failing to catch the exception would - but that's a different situation, IMO. D - Yes, since the question is whether this may stop execution. It certainly can, but as Ajith said, it's not guaranteed. For the rest I agree with Ajith.