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.
There are two methods that can directly affect the state of a thread:
Prevents a thread from running for an indefinite amount of time.
Allows a thread to run after being suspended.
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,
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 ...