Java-17.3 thread status
In this section, we will discuss the thread status.
1. Status
(1) New State (New): A New thread object is created.
(2) ready state (Runnable): After the thread object is created, other threads call the start () method of the object. The thread in this status is located in the runable thread pool and becomes runable, waiting to obtain the CPU usage right.
(3) Blocked: when a task wants to obtain the object lock, but the lock is held by another task, the status of the task is Blocked; when the Lock Object is held to release the lock, the task then holds the lock, and the task is not blocked.
(4) Waiting status (Waiting): When the thread waits for other threads to notify the scheduler to wake up for execution. This State occurs when methods such as Object. wait and Thread. join are executed.
(5) Time Waiting: the enhanced edition of the Waiting state, which increases the Waiting Time. When the timeout or notification is received, the thread will wake up and execute.
(6) Terminate: the thread has finished running or exited the run () method due to an exception.
2. Notes
The blocking status is different from the waiting status.
The blocking condition is related to the lock hold.
The waiting status is not necessarily related to the lock hold. It is related to some execution methods.
3. status chart
Summary: This chapter mainly discusses the thread status.
This chapter is here. Thank you.