Several available states of the thread

1. New (new): A thread object is newly created.
2. Runnable: After the thread object is created, other threads (such as the main thread) call the start () method of the object. Threads in this state are in the runnable thread pool, waiting to be selected by thread scheduling to obtain the right to use the CPU.
3. Running (running): The thread in the runnable state (runnable) obtains the cpu time slice (timeslice) and executes the program code.
4. Blocking (block): The blocking state means that the thread gives up the right to use the cpu for some reason, that is, gives up the cpu timeslice and temporarily stops running. Until the thread enters the runnable state, there is no chance to get the cpu timeslice to go to the running state again. There are three types of blocking:
(1). Waiting for blocking: The running (running) thread executes the o.wait() method, and the JVM will put the thread in the waiting queue (waiting queue).
(2) Synchronization blocking: When a running thread acquires the synchronization lock of an object, if the synchronization lock is occupied by another thread, the JVM will put the thread into the lock pool (lock pool).
(3). Other blocking: When a running (running) thread executes the Thread.sleep (long ms) or t.join () method, or issues an I/O request, the JVM will place the thread in a blocking state. When the sleep() state times out, the join() waits for the thread to terminate or times out, or when the I/O processing is complete, the thread re-enters the runnable state.
5. Dead (dead): The thread run (), main () method execution ends, or the run () method exits due to an exception, the thread ends its life cycle. Dead threads cannot be revived.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325729412&siteId=291194637