i

JAVA Complete Course

Java Thread Model

Before starting explaining actual thread model and multithreading in Java, let’s quickly review why it is beneficial to use threading. First of all, it must be mentioned that if we don’t use threading properly, instead of improvement, our performance can be decreased.

On the image there are the stages which thread can have. Let’s review each of it:

New – This is the state where the new thread begins its lifecycle. Thread will stay in this state until the program starts the it.

Runnable – After running of newly born thread, it will move to this state. A thread which is in Runnable state is considered to be executing its task.

Waiting – This is the state when a thread is waiting for another thread to finish its task. It will move again to the runnable state only when another thread give the signal of waiting thread to continue its task.

Timed Waiting – This is the same state as waiting, but when we have specific amount of time defined for waiting. It will move back to Runnable state when time interval expires or it gets signal.

Terminated (Dead) – After completing task, thread is moving to terminated state.