Thread life cycle thread state transitions
Thread state
Newly created (new)
Creates a thread.Thread t = new MyThread();
Ready (runnable)
The thread is in a state that can be scheduled for CPU at any time. Executes the start()
boot thread.
Run (running)
Threads are scheduled by the CPU and run continuously. Calls yield()
can yield CPU resources (not necessarily).
Blocking (blocked)
running
a thread in the state temporarily abandons the use of the CPU for some reason, stops execution until it enters the ready state, and then has the opportunity to be scheduled again by the CPU.
Wait for blocking: execution wait()
causes the thread to hang (locks are released). notify()
notifyAll()
The thread will not enter the state until the thread gets or messages runnable
.
Synchronization blocking: Failed to get synchronized
synchronization lock.
Other blocking:
- Execution
sleep(milliseconds)
(aborts execution at a given time, does not release the lock);
- Execution
join()
joins a thread, the original thread is suspended until the target thread ends;
- A request was made
I/O
.
Death (dead)
End of thread run (thread task execution complete/exception exit).
Thread life cycle