Java中线程的状态

一、java中线程的状态定义

  Thread的状态位于Thread的State枚举类中,对应的枚举分别为:

  NEW,RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED;

二、Java源码中关于State及各种状态说明

  1)State解释:

    A thread can be in only one state at a given point in time. These states are virtual machine states which do not reflect any operating system thread states.

    一个线程在意的给定的时间点,只能对应一种状态。这些状态是jvm中的状态不反映任何操作系统中的状态。

  2)关于各种状态的解释:

    //Thread state for a thread which has not yet started.  一个线程没开始运行前

    NEW

    // A thread in the runnable state is executing in the Java virtual machine but it may be waiting for other resources from the operating system such as processor.

    // 一个线程在jvm中执行,但是它对应的可能是操作系统中正在等待其他资源

    RUNNABLE

    //以下三种状态对应的都是操作系统角度线程的阻塞状态

    BLOCKED  WAITING  TIMED_WAITING  

    //The thread has completed execution  线程已经执行完成,状态为终止

    TERMINATED 

三、对应状态说明图:(以下图片引用自知乎)

 

posted @ 2018-03-22 10:55  zrx暖暖  阅读(170)  评论(0)    收藏  举报