java thread


1. New state (New): A thread object is newly created.

2. Ready state (Runnable): After the thread object is created, other threads call the start() method of the object. Threads in this state are in the runnable thread pool and become runnable, waiting to acquire the right to use the CPU.

3. Running state (Running): The thread in the ready state acquires the CPU and executes the program code.

4. Blocked state (Blocked): The blocked state is that the thread gives up the right to use the CPU for some reason and temporarily stops running. Until the thread enters the ready state, there is no chance to go to the running state. There are three types of blocking:

(1) Waiting for blocking: The running thread executes the wait() method, and the JVM will put the thread into the waiting pool. (wait will release the held lock)

(2) Synchronization blocking: When the running thread acquires the synchronization lock of the object, if the synchronization lock is occupied by another thread, the JVM will put the thread into the lock pool.

(3) Other blocking: When the running thread executes the sleep() or join() method, or issues an I/O request, the JVM will place the thread in a blocked state. When the sleep() state times out, join() waits for the thread to terminate or times out, or when the I/O processing is complete, the thread re-enters the ready state. (Note that sleep will not release the held lock)

5. Dead state (Dead): The thread finishes executing or exits the run() method due to an exception, and the thread ends its life cycle.


Guess you like

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