Java thread lifecycle and state transfer

 

The figure is a flow diagram lifecycle status of a thread, clearly depicts a thread process from creation to termination.

Enumeration value of these states are defined at java.lang.Thread.State

NEW: There is no doubt represents the thread you just created, has not yet started.

RUNNABLE: indicates that the thread has been triggered start () invoke, officially launched thread, the thread is running in the state.

BLOCKED: represents the thread to block waiting to acquire a lock, such as encounter synchronized, lock and other keywords such as the occupancy of the critical region, once the lock is to be acquired RUNNABLE state continues to run.

WAITING: indicates that the thread is not restricted waiting, waiting for a special event to re-awaken, such as waiting for a notify () or notifyAll () method wait () method waiting threads, a thread waits by the join () method waits the end goal thread runs wake, wake up the thread once through the relevant events, the thread into the RUNNABLE state continues to run.

TIMED_WAITING: indicates that the thread has entered a time of waiting, such as sleep (3000), re-thread RUNNABLE state continues to run after waiting for 3 seconds.

TERMINATED: After represents a thread of execution is completed, the termination status.

Note that, after the start method to start the thread can no longer return once the initial NEW state, after the termination of the thread can no longer return to RUNNABLE state.

Guess you like

Origin www.cnblogs.com/windpoplar/p/11827642.html