线程的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: 任务执行完了;
相关推荐
Json_17 分钟前
学习springBoot框架-开发一个酒店管理系统,熟悉springboot框架语法~
java·spring boot·后端
kkkkk02110625 分钟前
微服务学习笔记(黑马商城)
java·spring boot·spring·spring cloud·sentinel·mybatis·java-rabbitmq
2503_9301239326 分钟前
Kubernetes (六)调度策略详解:从节点匹配到Pod调度全流程
java·开发语言
YBN娜40 分钟前
设计模式-创建型设计模式
java·开发语言·设计模式
桦说编程1 小时前
CompletableFuture API 过于复杂?选取7个最常用的方法,解决95%的问题
java·后端·函数式编程
数智顾问1 小时前
Flink ProcessFunction 与低层级 Join 实战手册:多流广告计费精确去重
java·spring boot·spring
一头生产的驴1 小时前
java整合itext pdf实现固定模版pdf导出
java·python·pdf
魔都吴所谓1 小时前
【python】快速实现pdf批量去除指定位置水印
java·python·pdf
Camel卡蒙1 小时前
数据结构——字典树Trie(介绍、Java实现)
java·数据结构
kida_yuan1 小时前
【Java】基于 Tabula 的 PDF 合并单元格内容提取
java·数据分析