Monday 21 July 2014

Java Thread States

A thread in Java can have the following states:

  • NEW : First state, the thread is not yet begin being executed in this state.
  • RUNNABLE :  A thread executing in the JVM is in this state.
  • BLOCKED : A thread blocked waiting for a monitor lock will be in this state.
  • WAITING : A thread waiting for another thread without any time constraints will be in the WAITING state
  • TIME_WAITING : A thread waiting for another thread but with a upper time limit to wait will be in this state
  • TERMINATED : After a thread exits it will take the state TERMINATED
All the states are upper case because that is what the Thread.State enum will return when invoked.
All threads have one state and only one state every single moment of their existence.
Thread states are only related to the JVM execution and won't match the states of the processes ran by the operating system.

No comments:

Post a Comment