Different states of thread in Java

Upasana | November 21, 2020 | 2 min read | 33 views


A thread in JVM can have 6 different states as defined in Thread.State enum. At any given time, thread must be in any of these states.

NEW

This state is for a thread which has not yet started.

RUNNABLE

This state is for the currently running thread which is executing in java virtual machine, but it may be waiting for the other resources from operating system such as processor.

BLOCKED

Thread state for a thread blocked waiting for a monitor lock. A thread in this state can be waiting for a monitor lock to enter a synchronized block/method or reenter a synchronized method after calling Object.wait().

WAITING

A thread is waiting due to calling on one of the method -

  • Object.wait with no timeout

  • Thread.join with no timeout

  • LockSupport.park

A Thread in this state is waiting for another thread to perform a particular action. For example, a thread that has called Object.wait() on an object is waiting for another thread to call Object.notify() or Object.notifyAll() on that object. A thread that has called Thread.join() is waiting for a specified thread to terminate.

TIMED_WAITING

Thread state for a waiting thread with a specified waiting time. A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time -

  • Thread.sleep

  • Object.wait with timeout

  • Thread.join with timeout

  • LockSupport.parkNanos

  • LockSupport.parkUntil

TERMINATED

Thread state for a terminated thread. The thread has completed execution.

References

This content has been taken directly from the Java Docs - Thread.State enum.


Top articles in this category:
  1. Multi-threading Java Interview Questions for Investment Bank
  2. Morgan Stanley Java Interview Questions
  3. Java Concurrency Interview Questions
  4. Hibernate & Spring Data JPA interview questions
  5. Citibank Java developer interview questions
  6. Sapient Global Market Java Interview Questions and Coding Exercise
  7. UBS Java Interview Questions

Recommended books for interview preparation:

Find more on this topic: