Java Thread Status(转)
public static enum Thread.State? extends Enum<Thread.State>線程狀態。
線程可以處于下列狀態之一: 
1.NEW 至今尚未啟動的線程的狀態。 
2.RUNNABLE 可運行線程的線程狀態。
??????? 處于可運行狀態的某一線程正在 Java 虛擬機中運行,但它可能正在等待操作系統中的其他資源,比如處理器。 
3.BLOCKED 受阻塞并且正在等待監視器鎖的某一線程的線程狀態。
??????? 處于受阻塞狀態的某一線程正在等待監視器鎖,以便進入一個同步的塊/方法,或者在調用 Object.wait 之后再次進入同步的塊/方法。
4.WAITING 某一等待線程的線程狀態。某一線程因為調用下列方法之一而處于等待狀態:
- 不帶超時值的 Object.wait
- 不帶超時值的 Thread.join
LockSupport.park
處于等待狀態的線程正等待另一個線程,以執行特定操作。
 例如,已經在某一對象上調用了 Object.wait() 的線程正等待另一個線程,以便在該對象上調用 Object.notify() 或 Object.notifyAll()。
??? 已經調用了 Thread.join() 的線程正在等待指定線程終止。
5.TIMED_WAITING具有指定等待時間的某一等待線程的線程狀態。某一線程因為調用以下帶有指定正等待時間的方法之一而處于定時等待狀態:
- Thread.sleep
- 帶有超時值的 Object.wait
- 帶有超時值的 Thread.join
- LockSupport.parkNanos
- LockSupport.parkUntil
 
6.TERMINATED
已終止線程的線程狀態。線程已經結束執行。
注意:在給定時間點上,一個線程只能處于一種狀態。這些狀態是虛擬機狀態,它們并沒有反映所有操作系統線程狀態。
為了展現線程在運行時的狀態及其轉換,我畫了下面這個圖
?
/*** A thread state. A thread can be in one of the following states:* <ul>* <li>{@link #NEW}<br>* A thread that has not yet started is in this state.* </li>* <li>{@link #RUNNABLE}<br>* A thread executing in the Java virtual machine is in this state.* </li>* <li>{@link #BLOCKED}<br>* A thread that is blocked waiting for a monitor lock* is in this state.* </li>* <li>{@link #WAITING}<br>* A thread that is waiting indefinitely for another thread to* perform a particular action is in this state.* </li>* <li>{@link #TIMED_WAITING}<br>* A thread that is waiting for another thread to perform an action* for up to a specified waiting time is in this state.* </li>* <li>{@link #TERMINATED}<br>* A thread that has exited is in this state.* </li>* </ul>** <p>* A thread can be in only one state at a given point in time.* These states are virtual machine states which do not reflect* any operating system thread states.** @since 1.5* @see #getState*/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;}java.lang.Thread.State
?
?
http://www.blogjava.net/cpegtop/articles/377980.html
轉載于:https://www.cnblogs.com/softidea/p/3984146.html
總結
以上是生活随笔為你收集整理的Java Thread Status(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 2021五一建模a题完整论文
- 下一篇: stm32中stm32f10x_type
