Back-End/Java_1

[Java] Life cycle of a thread

리딩리드 2016. 10. 5. 14:29

Life cycle of a thread

- According to sun, there is only 4 states, new, runnable, non-runnable and terminated

- but this post I referred consist of 5 states to better understand the threads

1. New

- The thread is in new state 

- If you create an instance of Thread class 

2. Runnable

- The thread is in runnable state after invocation of start()

- the thread scheduler has not selected it to be the running thread

- sleep done, I/O complete, lock available, resume, notify

3. Running

- The thread is in running state

- The thread scheduler has selected it

4. Non-Runnable(Blocked)

- This is the state when the thread is sill alive

- it is currently not eligible to run

- sleep, block on I/O, wait for lock, suspend, wait

5. Terminated

- Dead state when its run() method exits