Detailed explanation of Java thread state

Thread state classification

1. New state (New)

When a thread object is created, but its start () method has not been called, it is in the new state. (The corresponding PCB has not been created in the kernel yet)

2. Terminated state (Terminated)

When the thread's run() method is executed or the thread is forcibly terminated, the thread enters the terminated state. (Indicates that the PCB in the kernel has been executed, but the Thread object is still there)

3. Ready state (Runnable)

When the thread object calls the start() method, the thread enters the ready state. There are two cases:

  • Executing on the CPU
    - in the ready queue, ready to execute on the CPU at any time

4. Blocked state (Blocked)

Under certain circumstances, a thread may be blocked, suspending execution. Common blocking situations include waiting for input/output, waiting for locks, or other resources. When these conditions are met, the thread will enter the blocked state.

5. Waiting state (Waiting)

Threads actively wait under certain conditions, such as calling the wait() method. In the wait state, the thread will wait until it is woken up or it times out.

6. Timed waiting state (Timed Waiting)

Similar to a wait state, but waits for a specified amount of time, such as calling the sleep() method or the wait() method with a timeout parameter.
Among them, 4, 5, and 6 are blocked (indicating that the thread PCB is in the blocking queue)

thread state transition

The following is a simple example diagram:
insert image description here

Guess you like

Origin blog.csdn.net/m0_63904107/article/details/131541122