Originally posted by Mohit Agarwal:
Why alternate E is correct .
please throw some light on this.
Which two can directly cause a thread to stop executing? (Choose Two)
A. Exiting from a synchronized block.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the setPriority method on a thread object.
Answer: B, E
The thread scheduler will frequently (but certainly not always) schedul OUT a thread if a thread of higher priority is available (runnable) and make the HIGHER priority thread execute. (running)
If the thread which currently has the processor is changed to a lower priority, a higher priority thread may be scheduled to execute by the thread scheduler.
It's debatable if this can be viewed as "directly cause a thread to stop executing" because it's the THREAD SCHEDULER that's directly causing the thread to stop executing. (Unlike the
test, I'm making assumptions about the test-writer's INTENTION vs. the wording).