Java Thread Status(转)
public static enum Thread.State? extends Enum<Thread.State>線程狀態(tài)。
線程可以處于下列狀態(tài)之一:
1.NEW 至今尚未啟動的線程的狀態(tài)。
2.RUNNABLE 可運行線程的線程狀態(tài)。
??????? 處于可運行狀態(tài)的某一線程正在 Java 虛擬機中運行,但它可能正在等待操作系統(tǒng)中的其他資源,比如處理器。
3.BLOCKED 受阻塞并且正在等待監(jiān)視器鎖的某一線程的線程狀態(tài)。
??????? 處于受阻塞狀態(tài)的某一線程正在等待監(jiān)視器鎖,以便進入一個同步的塊/方法,或者在調(diào)用 Object.wait 之后再次進入同步的塊/方法。
4.WAITING 某一等待線程的線程狀態(tài)。某一線程因為調(diào)用下列方法之一而處于等待狀態(tài):
- 不帶超時值的 Object.wait
- 不帶超時值的 Thread.join
LockSupport.park
處于等待狀態(tài)的線程正等待另一個線程,以執(zhí)行特定操作。
例如,已經(jīng)在某一對象上調(diào)用了 Object.wait() 的線程正等待另一個線程,以便在該對象上調(diào)用 Object.notify() 或 Object.notifyAll()。
??? 已經(jīng)調(diào)用了 Thread.join() 的線程正在等待指定線程終止。
5.TIMED_WAITING具有指定等待時間的某一等待線程的線程狀態(tài)。某一線程因為調(diào)用以下帶有指定正等待時間的方法之一而處于定時等待狀態(tài):
- Thread.sleep
- 帶有超時值的 Object.wait
- 帶有超時值的 Thread.join
- LockSupport.parkNanos
- LockSupport.parkUntil
6.TERMINATED
已終止線程的線程狀態(tài)。線程已經(jīng)結(jié)束執(zhí)行。
注意:在給定時間點上,一個線程只能處于一種狀態(tài)。這些狀態(tài)是虛擬機狀態(tài),它們并沒有反映所有操作系統(tǒng)線程狀態(tài)。
為了展現(xiàn)線程在運行時的狀態(tài)及其轉(zhuǎn)換,我畫了下面這個圖
?
/*** 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
轉(zhuǎn)載于:https://www.cnblogs.com/softidea/p/3984146.html
總結(jié)
以上是生活随笔為你收集整理的Java Thread Status(转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021五一建模a题完整论文
- 下一篇: java美元兑换,(Java实现) 美元