Thread Lifecycle

A thread can exist in multiple states: NEW, RUNNABLE, WAIT, TIMED_WAITING, BLOCKED, or TERMINATED. A thread doesn’t begin its execution with its instantiation. Figure below shows the various phases of a thread, including the methods that can be called on a thread object in each state, which makes it transition from one state to another.

Note:

Thread scheduling is specific to the underlying OS on every system. As a programmer, you can’t control or determine when a particular thread transitions from the READY state to the RUNNING state, and when it actually gets to execute. A thread scheduler fol- lows various scheduling mechanisms to utilize a processor efficiently, and also to give a fair share of processor time to each thread. It might suspend a running thread to give way to other READY threads and it might execute it later. The READY and the RUNNING states are together referred to as the RUNNABLE state.

Last updated