线程的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: 任务执行完了;
相关推荐
魔芋红茶1 分钟前
Netty 简易指南
java·开发语言·netty
大学生资源网20 分钟前
基于springboot的万亩助农网站的设计与实现源代码(源码+文档)
java·spring boot·后端·mysql·毕业设计·源码
小严家22 分钟前
Java基础教程大全完整学习路径
java·开发语言·学习
毕设源码-朱学姐23 分钟前
【开题答辩全过程】以 基于Java的电影推荐系统为例,包含答辩的问题和答案
java·开发语言
sheji341629 分钟前
【开题答辩全过程】以 基于SSM的校园新冠疫苗接种信息管理系统为例,包含答辩的问题和答案
java·开发语言
菜鸟233号30 分钟前
力扣78 子集 java实现
java·数据结构·算法·leetcode
dddaidai12339 分钟前
深入JVM(四):垃圾收集器
java·开发语言·jvm
BBB努力学习程序设计1 小时前
Java方法(函数)完全指南:初学者的第一个"工具箱"
java
爬山算法1 小时前
Netty(19)Netty的性能优化手段有哪些?
java·后端
love is sour1 小时前
深入浅出 jmap:Java 内存分析的“显微镜“
java·开发语言·测试工具·性能优化