Thursday, 9 February 2017

DIFFERENT STATES IMPLEMENTING MULTI-THREAD IN JAVA



As we have seen different states that may be occur with the single thread, a running thread can enter to any non-runnable state, depending on the circumstances. A thread cannot enter directly to the running state from non-runnable state, first it goes to runnable state. Now let’s understand some non-runnable states which may occur while handling the multithreads.

Sleeping – On this state, the thread is still alive but it is not runnable, it might return to runnable state later, if a particular event occurs. On this state a thread sleeps for a specified amount of time, we can use the method sleep() to stop running state of a thread.
§  static void sleep(long millisecond) throws InterruptedException

Waiting for Notification – A thread waits for notification from another thread. The thread sends back to runnable state after sending notification from another thread.
§  final void wait(long timeout) throws InterruptedException
§  final void wait(long timeout, int nanos) throws InterruptedException
§  final void wait() throws InterruptedException

Blocked on I/O – The thread waits for completion of blocking operation. A thread can enter in this state because of waiting I/O resource. In that case, the thread sends back to runnable state after availability of resources.

Blocked for join completion – The thread can come to this state, while waiting for the completion of another thread execution.

Blocked for lock acquisition – The thread can come to this state, while waiting to acquire the lock of an object. 

No comments:

Post a Comment