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.
This state is for a thread which has not yet started.
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.
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
A thread is waiting due to calling on one of the method -
Object.wait with no timeout
Thread.join with no timeout
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.notifyAll() on that object. A thread that has called
Thread.join() is waiting for a specified thread to terminate.
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 -
Object.wait with timeout
Thread.join with timeout
Thread state for a terminated thread. The thread has completed execution.
This content has been taken directly from the Java Docs - Thread.State enum.
Top articles in this category:
- Multi-threading Java Interview Questions for Investment Bank
- Morgan Stanley Java Interview Questions
- Java Concurrency Interview Questions
- Citibank Java developer interview questions
- Hibernate & Spring Data JPA interview questions
- Sapient Global Market Java Interview Questions and Coding Exercise
- UBS Java Interview Questions