java 线程的状态

介绍: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:阻塞 等待监视器锁定被阻止的线程处于此状态。 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值