java 线程的几种状态

现在是jdk中java线程状态的源码。

public enum State {
        /**
         * Thread state for a thread which has not yet started.
         */
        NEW, //新建状态,该线程还没有执行start方法

        /**
         * 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,// 就绪状态,也就是线程执行了start()方法。但是还没分配到cpu资源。未能真正执行

        /**
         * 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:
         * 
    *
  • {@link Object#wait() Object.wait} with no timeout
  • *
  • {@link #join() Thread.join} with no timeout
  • *
  • {@link LockSupport#park() LockSupport.park}
  • *
* *

A thread in the waiting state is waiting for another thread to * perform a particular action. * * For example, a thread that has called Object.wait() * on an object is waiting for another thread to call * Object.notify() or Object.notifyAll() on * that object. A thread that has called Thread.join() * is waiting for a specified thread to terminate. */ WAITING,// 等待状态,等待状态的原因是执行了Object.wait,Thread.join,park()。正在等待其他线程的操作来唤醒 /** * 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: *

    *
  • {@link #sleep Thread.sleep}
  • *
  • {@link Object#wait(long) Object.wait} with timeout
  • *
  • {@link #join(long) Thread.join} with timeout
  • *
  • {@link LockSupport#parkNanos LockSupport.parkNanos}
  • *
  • {@link LockSupport#parkUntil LockSupport.parkUntil}
  • *
*/ TIMED_WAITING,// 定时等待,原因是使用了Thread.sleep,Thread.join,wait(long) Object.wait带有限时参数,另外还有LockSupport.parkNanos,LockSupport.parkUntil /** * Thread state for a terminated thread. * The thread has completed execution. */ TERMINATED;// 结束状态,任务执行完了 }

 

你可能感兴趣的:(java并发编程)