Other Thread-Scheduling Methods
There are other methods in the Thread class that affect scheduling. As we’ll see, these remaining methods are not always the most useful techniques with respect to Java scheduling because of the complications that arise in the various native-thread scheduling models and their use of timesliced scheduling. In addition, two of these methods have been deprecated in Java 2 and should not be used in any version of Java. But we’ll complete our look at the API relating to thread scheduling in this section.
The suspend() and resume() Methods
There are two methods that can directly affect the state of a thread:
- void suspend() (deprecated in Java 2)
Prevents a thread from running for an indefinite amount of time.
- void resume() (deprecated in Java 2)
Allows a thread to run after being suspended.
The suspend() method moves a particular thread
from the runnable state into the blocked state. In this case, the
thread isn’t blocked waiting for a particular resource,
it’s blocked waiting for some thread to resume it. The
resume() method moves the thread from the
blocked state to the runnable state.
In the section Section 6.1,” earlier in this
chapter, we posited the existence of four thread states. Actually,
the
suspended state is different from the
blocked state, even though there is no real conceptual difference
between them. Strictly speaking, the suspend() method moves a thread to the suspended state from whatever state the thread was previously in—including a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access