In this chapter we discuss the state of the thread.
1. Status
(1) New status (new): Newly created Thread object
(2) Ready State (Runnable): After the thread object is created, other threads call the object's start () method. The state of the thread is located in a pool of running threads that becomes operational and waits for the CPU to be used.
(3) Blocking state (Blocked): When a task wants to acquire an object lock, but the lock is held by another task, the state of the task is blocked state, and when the lock object is held to release the lock, then the task holds the lock, at which point the task is non-blocking state.
(4) Wait state (waiting): When the thread waits for another thread to notify the scheduler to wake execution. This state is more present when Object.wait,thread.join and other methods are executed.
(5) Timed Wait (time waiting): The wait status of the enhanced version, increased the waiting period, when the time-out or received notification, the thread will wake up execution.
(6) Death status (Terminate): The thread finishes executing or exits the run () method due to an exception, and the thread ends the life cycle.
2. Attention points
The blocking state is not the same as the wait state.
The condition of blockage formation is related to the holding of locks.
The wait state is not necessarily related to the hold of the lock, it is related to some execution methods
3. State diagram
Summary: This chapter focuses on the state of the thread.
This chapter is here, thank you.
-----------------------------------
Directory
Understanding java-17.3 thread state from the beginning