线程的6中状态

这个6中状态是Java Thread类中的枚举值中来的。

java 复制代码
 public enum State {
        /**
         * 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,

        /**
         * Thread state for a thread blocked waiting for a monitor lock.
         * A thread in the blocked state is waiting for a monitor lock
         * to enter a synchronized block/method or
         * reenter a synchronized block/method after calling
         * {@link Object#wait() Object.wait}.
         */
        BLOCKED,

        /**
         * Thread state for a waiting thread.
         * A thread is in the waiting state due to calling one of the
         * following methods:
         * <ul>
         *   <li>{@link Object#wait() Object.wait} with no timeout</li>
         *   <li>{@link #join() Thread.join} with no timeout</li>
         *   <li>{@link LockSupport#park() LockSupport.park}</li>
         * </ul>
         *
         * <p>A thread in the waiting state is waiting for another thread to
         * perform a particular action.
         *
         * For example, a thread that has called <tt>Object.wait()</tt>
         * on an object is waiting for another thread to call
         * <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on
         * that object. A thread that has called <tt>Thread.join()</tt>
         * is waiting for a specified thread to terminate.
         */
        WAITING,

        /**
         * Thread state for a waiting thread with a specified waiting time.
         * A thread is in the timed waiting state due to calling one of
         * the following methods with a specified positive waiting time:
         * <ul>
         *   <li>{@link #sleep Thread.sleep}</li>
         *   <li>{@link Object#wait(long) Object.wait} with timeout</li>
         *   <li>{@link #join(long) Thread.join} with timeout</li>
         *   <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li>
         *   <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li>
         * </ul>
         */
        TIMED_WAITING,

        /**
         * Thread state for a terminated thread.
         * The thread has completed execution.
         */
        TERMINATED;
    }

new : 就是创建了线程对象 但是还没有调用start 方法;

RUNNABLE: 线程正在执行任务;

复制代码
BLOCKED: 阻塞状态,当前线程还没有抢到锁,就等在原地一直发呆的过程;
复制代码
WAITING:当前线程拿到了CPU的执行权,但是由于某种原因还没开始执行自己的任务;
复制代码
TIMED_WAITING: 调用了设置了等待时间的方法
复制代码
TERMINATED: 任务执行完了;
相关推荐
笨蛋不要掉眼泪11 分钟前
Spring Boot集成腾讯云人脸识别实现智能小区门禁系统
java·数据库·spring boot
桃源学社(接毕设)14 分钟前
云计算下数据隐私保护系统的设计与实现(LW+源码+讲解+部署)
java·云计算·毕业设计·swing·隐私保护
用户03321266636729 分钟前
Java 将 Excel 转换为 HTML:解锁数据在线展示的无限可能
java·excel
字节跳跃者1 小时前
SpringBoot + MinIO + kkFile 实现文件预览,这样操作更安全!
java·后端·程序员
天天摸鱼的java工程师1 小时前
OpenFeign 首次调用卡 3 秒?八年老开发扒透 5 个坑,实战优化到 100ms
java·后端·面试
whitepure1 小时前
万字详解Java集合
java·后端
华仔啊1 小时前
乐观锁、悲观锁和分布式锁,你用对了吗?
java·分布式
自由的疯1 小时前
Java下载图片并导出压缩包
java·后端·trae
tanxiaomi1 小时前
Spring面试宝典:Spring IOC的执行流程解析
java·spring·面试
NightDW2 小时前
连续周更任务模块的设计与实现
java·后端·mysql