In this blog post we will discuss about one of the very important java interview question What are different states of a Thread? What does those states tell us?
A thread can have 6 different states as defined in Thread.State enum within thread class. At any given point of time, thread must be in any of these states.
- A thread is in NEW state when thread just created but 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.
- When a thread said to be BLOCKED state if 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 wait()
- A thread is waiting due to calling on one of the method –
- wait with no timeout
- join with no timeout
When a thread said to be TIMED_WAITING state if a waiting thread with a specified waiting time. A thread is in the TIMED_WAITING state due to calling any one of the following methods with a specified positive waiting time –
- wait with timeout
- join with timeout
- Thread state for a terminated thread. The thread has completed execution.
You may also like:
That’s all about What are different states of a Thread? What does those states tell us?
If you have any feedback or suggestion please feel free to drop in blow comment box.