Difficulty: Easy
Correct Answer: Calling setPriority() on a Thread object
Explanation:
Introduction / Context:
Many APIs influence a thread’s execution state. Some block the current thread immediately; others merely request a change or affect different threads. Here we identify the call that does not directly deschedule the caller.
Given Data / Assumptions:
Concept / Approach:setPriority()
changes the scheduling priority but does not itself block or stop the caller. By contrast, wait()
blocks the current thread, sleep()
blocks the current thread, and I/O such as InputStream.read()
often blocks until data is available. notify()
affects waiting threads but does not block the caller; however, it also does not stop the caller.
Step-by-Step Reasoning:
Verification / Alternative check:
Javadoc behavior for the listed methods shows which ones are blocking versus non-blocking.
Why Other Options Are Wrong:
They represent blocking calls (wait/sleep/read) or do not answer the “cannot directly cause” aspect correctly.
Common Pitfalls:
Assuming priority changes force an immediate context switch; assuming notify()
blocks the caller (it does not).
Final Answer:
Calling setPriority() on a Thread object
Discussion & Comments