One, thread state
The state transition of a thread is the basis of thread control. The total thread state can be divided into five states: raw, dead, can run, run, wait / block . This is described in a diagram as follows:
1. New state: The thread object has been created and the start () method has not been invoked on it .
2. Operational status: When the thread is eligible to run, but the scheduler has not selected it as the state in which the thread is running. When the start () method is called, the thread first enters the operational state. After the thread has run or has returned from blocking, waiting, or sleeping, it returns to the operational state.
3. Running state: The thread Scheduler selects a thread from a running pool as the current thread is in the state of the thread. This is also the only way that a thread goes into a running state.
4. Wait / block / sleep state: This is the state at which the thread is eligible to run. In fact, this three-state combination is one, and its common denominator is that the thread is still alive, but there is no condition to run at the moment. In other words, it is operational, but if an event occurs, he may return to the operational state.
5. Death state: When the thread's run () method finishes, it is considered dead. This thread object may be alive, but it is not a separate thread. Once a thread dies, it cannot be resurrected. If you call the start () method on a dead thread , the java.lang.IllegalThreadStateException exception is thrown .
Changes in Java thread State