Java 线程生命周期

2022-09-06  本文已影响0人  Tinyspot

1. 线程状态

1.1 操作系统层面(5种)

1.2 Java API 层面(6种)

thread-state

2. java.lang.Thread.State

public enum State {
  NEW,

  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 Object.wait.
  */
  BLOCKED,
  /**
    * Object.wait with no timeout
    * Thread.join with no timeout
    * LockSupport.park (显示调用,还有隐式调用,如 BlockingQueue的 take 和 put)
    */
  WAITING,
  /**
  * Thread.sleep
  * Object.wait with timeout
  * Thread.join with timeout
  * LockSupport.parkNanos
  * LockSupport.parkUntil
  */
  TIMED_WAITING,

  TERMINATED;
}
上一篇下一篇

猜你喜欢

热点阅读