Thread state transition in java

Enum Thread.State is defined to describe thread’s status in Thread.java. One java thread is one system thread. But the state is not system thread's status it's what management or marked by JVM.

  1. NEW. When a thread instance is created but not startd,it's in new state.
  2. RUNNABLE. When the thread starts and executes in JVM, it’s in runnable state.
  3. BLOCKED. When the thread is waiting for monitor lock, it’s in blocked state.
  4. WAITING. When the thread is in object’s wait set but no waiting time set, it’s in waiting state.
  5. TIMED_WAITING. Thread is in waiting state with a specified waiting time.
  6. TERMINATED. A thread completes(normal or abnormal) is in terminated state.

Notice that thread’s join and sleep methods have nothing to do with object monitor. So when they exit, the thread can turn into runnable state directly. However, this is not the case with obj.wait(), in which case the thread needs to contend for object lock again after exit.