线程的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: 任务执行完了;
相关推荐
bxlj_jcj3 分钟前
深入剖析Debezium:CDC领域的“数据魔法棒”
java·架构
叶 落28 分钟前
ubuntu 安装 JDK8
java·ubuntu·jdk·安装·java8
爱学习的白杨树31 分钟前
Sentinel介绍
java·开发语言
XW39 分钟前
java mcp client调用 (modelcontextprotocol)
java·llm
保持学习ing2 小时前
SpringBoot前后台交互 -- 登录功能实现(拦截器+异常捕获器)
java·spring boot·后端·ssm·交互·拦截器·异常捕获器
gadiaola2 小时前
【JVM面试篇】高频八股汇总——类加载和类加载器
java·jvm·面试
七七&5562 小时前
【Java开发日记】基于 Spring Cloud 的微服务架构分析
java·spring cloud·架构
小猫咪怎么会有坏心思呢2 小时前
华为OD机考-数字游戏-逻辑分析(JAVA 2025B卷)
java·游戏·华为od
Aesopcmc2 小时前
idea 启动jar程序并调试
java·intellij-idea·jar
南极Ou3 小时前
Mybatis逆向工程详解(附源码文件)动态创建实体类、条件扩展类、Mapper接口、Mapper.xml映射文件
xml·java·mybatis