日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java Thread Status(转)

發(fā)布時間:2023/12/9 java 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java Thread Status(转) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。