Home >Java >JavaBase >Introduction to several states of java threads

Introduction to several states of java threads

尚
Original
2019-12-26 13:48:393435browse

Introduction to several states of java threads

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:

Introduction to several states of java threads

(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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to sort java arrayNext article:How to sort java array