其他分享
首页 > 其他分享> > 2022-02-03 线程生命周期

2022-02-03 线程生命周期

作者:互联网

概念
生命周期可以通俗地理解为“从摇篮到坟墓”(Cradle-to-Grave)的整个过程。线程的生命周期包括从创建到终结的整个过程。
我们在Thread类中发现了一个内部枚举类,这个State就可以表示一个线程的生命周期:

public enum State {
/**
状态 描述
【NEW】 这个状态主要是线程未被Thread.start()调用前的
【RUNNABLE】 线程正在JVM中被执行,等待来自操作系统(如处
【BLOCKED】 阻塞,因为某些原因不能立即执行需要挂起等待
【WAITING】无限期等待,由于线程调用了Object.wait(0) Thread.join(0)和LockSupport.park 其中的处于等待状态,其中调用wait , join方法时未设有限期等待, 线程等待一个指定的时间,比如线这个枚举类阐述了一个线程的生命周期中,总共有以下6种状态
* Thread state for a thread which has not yet started.
*/

NEW,

/**
* Thread state for a runnable thread. 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.
*/

RUNNABLE,
BLOCKED,
WAITING,
TIMED_WAITING,
TERMINATED;
}

状态介绍
在这里插入图片描述
状态关系图
在这里插入图片描述

标签:02,03,生命周期,Thread,WAITING,state,线程,等待
来源: https://blog.csdn.net/qq_46049113/article/details/122777598