美文网首页
Java线程状态转换

Java线程状态转换

作者: 一切重新来 | 来源:发表于2018-04-08 14:08 被阅读0次

线程状态类型

在java.long.Thread类的内部定义了一个枚举

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;
    }
  1. 新建状态(NEW)
  2. 就绪状态(RUNNABLE)
  3. 运行状态
  4. 阻塞状态(BLOCKED)
  5. 死亡状态

相关文章

  • Java 线程的七种状态

    本篇感性地介绍一下 Java 线程的七种状态以及状态之间的转换 Java 线程状态转换图 Java 线程状态 在 ...

  • JAVA多线程及线程状态转换

    Java多线程及线程状态转换 - 祖华 - 博客园

  • Java线程状态及其转换

    线程状态及其转换 一、线程状态 Java中定义线程的状态有6种,可以查看Thread类的State枚举: 初始(N...

  • Java线程状态转换

    线程状态类型 在java.long.Thread类的内部定义了一个枚举 新建状态(NEW) 就绪状态(RUNNAB...

  • JAVA线程生命周期

    JAVA线程生命周期 摘要 本文详细总结了java线程的五种基本状态,和状态之间的转换关系;介绍了常见了创建线程的...

  • 2018-11-11

    如何新建一个线程? 线程状态是怎样转换的? 关于线程状态的操作是怎样的? 1. 新建线程 一个java程序从mai...

  • 一张图让你看懂JAVA线程间的状态转换

    原作者:程明东原博客链接:一张图让你看懂JAVA线程间的状态转换 线程间的状态转换: 1. 新建(new):新创建...

  • java线程状态及转换

    java线程状态:new(新建),runnable(就绪),running(运行),blocked(阻塞),dea...

  • Java 线程的状态及状态转换

    通用的线程周期 操作系统中,线程的状态一般包含以下五种:初始状态、可运行状态、运行状态、休眠状态、终止状态 初始状...

  • JAVA线程间的状态转换

    了解一个东西最好的方式,就是去看源码,只要源码不会骗你。 解惑:下面罗列的这些文章,看一遍,反正每篇文章的出发点都...

网友评论

      本文标题:Java线程状态转换

      本文链接:https://www.haomeiwen.com/subject/bsgphftx.html