Java中线程的状态类型

线程的状态类型

源码作者的原注释关于线程内部类State描述了线程的六个状态

  • A thread state. A thread can be in one of the following states:

①、NEW

  • 尚未启动的线程处于此状态
  • 源码中的注释
    • A thread that has not yet started is in this state.

②、RUNNABLE

  • Java虚拟机中执行的线程处于这种状态
  • 源码中的注释
    • A thread executing in the Java virtual machine is in this state.

③、BLOCKED

  • 被组织等待监视器锁定的线程处于此状态
  • 源码中的注释
    • A thread that is blocked waiting for a monitor lock is in this state.

④、WATING

  • 无限期等待另一个线程执行特定操作的线程处于此状态
  • 源码中的注释
    • A thread that is waiting indefinitely for another thread to perform a particular action is in this state.

⑤、TIMED_WATING

  • 一个线程等待另一个线程执行操作,在指定的等待时间内处于此状态

  • 源码中的注释

    • A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state

⑥、TERMINATED

  • 退出的线程处于此状态
  • 源码中的注释
    • A thread that has exited is in this state.

小结

  • 可以用一个枚举类来说明线程的这几个状态