介绍:Java中线程的状态分为6种。Thread类里面定义了枚举类State,里面详细的介绍了6种状态。如下(直接copy的 小小的用百度翻译了一下,(●'◡'●)):
NEW、RUNNABLE、BLOCKED、WAITING、TIMED_WAITING、TERMINATED
/**
* A thread state. A thread can be in one of the following states:
* <ul>
* <li>{@link #NEW}<br>
* A thread that has not yet started is in this state.
* 尚未启动的线程处于此状态。
* </li>
* <li>{@link #RUNNABLE}<br>
* A thread executing in the Java virtual machine is in this state.
* Java虚拟机中执行的线程处于此状态。
* </li>
* <li>{@link #BLOCKED}<br>
* A thread that is blocked waiting for a monitor lock is in this state.
* 等待监视器锁定被阻止的线程处于此状态。
* </li>
* <li>{@link #WAITING}<br>
* A thread that is waiting indefinitely for another thread to
* perform a particular action is in this state.
* 无限期等待另一线程执行特定操作的线程处于此状态。
* </li>
* <li>{@link #TIMED_WAITING}<br>
* A thread that is waiting for another thread to perform an action
* for up to a specified waiting time is in this state.
* 在指定等待时间内等待另一线程执行操作的线程处于此状态。
* </li>
* <li>{@link #TERMINATED}<br>
* A thread that has exited is in this state.
* 已退出的线程处于此状态。
* </li>
* </ul>
*
* <p>
* 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.
* 一个线程在给定时间点只能处于一种状态。这些状态是不反映任何操作系统线程状态的虚拟机状态。
*
* @since 1.5
* @see #getState
*/
实例: 下面我们就一一来验证这些状态:
NEW:初始状态 - 新创建了一个线程对象,但还没有调用start()方法。

RUNNABLE: 后面深入继续讲解这个的

BLOCKED:阻塞 等待监视器锁定被阻止的线程处于此状态。
1866

被折叠的 条评论
为什么被折叠?



