Java Thread States and Life Cycle

Thread is a lightweight sub-process. The state diagram below shows Java thread state change and life cycle.

ThreadStates

New – A thread is created. At the point, the thread is not alive yet.

Runnable – When start() method is called on the thread object, its state is changed to Runnable state. Thread scheduler will decide to run this thread now or keep it in runnable thread pool based on its priorities.

Running – When scheduler choose it from the runnable thread pool to execute, the thread’s state moves Running state. Thread scheduler picks one of the thread from the runnable thread pool and change it’s state to Running and CPU starts executing this thread.

Waiting -the thread in the waiting state is waiting for another thread to do something, and then it has chance to move to Runnable state. Case 1: a thread has called wait() before, another thread calls notify() or notifyAll(). Case 2: a thread has called join() before, and it is waiting for a specified thread to terminate.

Sleeping – Sleeping is a timed waiting state. In this state, a thread is suspended, and will wait a fixed time, and then move to Runnable state.

Blocked – When it waits for the monitor lock to enter a synchronized block/method, the thread is in Blocked state. Once the thread obtains the lock, it will moves to Running state.

Dead – Once the thread finish run() execution, it is moved to Dead state.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">