The five major states of threads and their transitions:
The five major states of threads are: creation state (New), ready state (Runnable), running state (Running) , blocked state (Blocked), dead state (Dead).
The following is a diagram of the relationship between the five major thread states:
(1) New state: simply create a thread, there are three types of thread creation The method can be viewed on my blog: Thread Creation!
(2) Ready state: After creating a thread, call the start() method of the Thread class to start a thread, which means that the thread enters the ready state!
(3) Running state: When the thread gets CPU time, the thread enters the running state from the ready state!
(4) Blocking state: After the thread enters the running state, the thread may enter the blocking state due to various reasons, such as: calling the sleep() method to make the thread sleep, calling the wait() method to make the thread wait, calling join() method, suspend() method (it is now deprecated!) and blocking IO method.
(5) Death state: The normal exit of the run() method will put the thread into the death state, and when an exception is not caught and terminates the execution of the run() method, it will also enter the death state. !
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Introduction to several states of java threads. For more information, please follow other related articles on the PHP Chinese website!