What are different thread states in Java

Carvia Tech | July 05, 2019 | | 0 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. Top 50 Multi-threading Java Interview Questions for Investment Bank
  2. Citibank Java developer interview questions
  3. Morgan Stanley Investment Banking Java Interview Questions
  4. RBS Java Programming Interview Questions
  5. Top 20 Java Concurrency Interview Questions and Answers
  6. BlackRock Top Java Interview Questions: Investment Banking Domain
  7. Goldman Sachs Java Interview Questions for Senior Developer



Find more on this topic:
Java Interviews image
Java Interviews

Interview - Product Companies, eCommerce Companies, Investment Banking, Healthcare Industry, Service Companies and Startups.

Last updated 1 week ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info