State Diagram of Java Thread

Figure:  Java thread state diagram

Runnable:  A thread becomes runnable when start() is called. It doesn’t mean that thread gets running immediately, rather it is pooled waiting for its turn to be picked for execution by the thread scheduler based on thread priorities.

Running: A thread started its execution when scheduler picks. It runs until it is blocked or voluntarily gives up its turn with this static method Thread.yield( ).

Waiting: A thread is in a blocked state while it waits for some external processing such as file I/O to finish. A call to current Object.wait( ) method causes the current thread to wait until some other thread invokes current Object.notify( ) or the current Object.notifyAll( ) is executed.

Sleeping: Java threads are forcibly put to sleep (suspended) with this overloaded method: Thread.sleep(milliseconds), Thread.sleep(milliseconds, nanoseconds);

Blocked on I/O: it moves to runnable after I/O condition like reading bytes of data etc. changes.

Blocked on synchronization: it moves to running when a lock is acquired.

Dead: The thread is finished working.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s