這篇文章主要介紹“JAVA線程一共有幾種狀態(tài)”,在日常操作中,相信很多人在JAVA線程一共有幾種狀態(tài)問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”JAVA線程一共有幾種狀態(tài)”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)專注于紅花崗企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),成都做商城網(wǎng)站。紅花崗網(wǎng)站建設(shè)公司,為紅花崗等地區(qū)提供建站服務(wù)。全流程按需求定制設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
線程的狀態(tài),在你*度的過程中,你會發(fā)現(xiàn),答案有5種,6種,甚至還有7種的,那么究竟有幾種狀態(tài)?
在編譯器JDK1.5以后的環(huán)境下,打開Thread進入源碼看看:
* A thread state. A thread can be in one of the following states:
* 一個線程,有以下幾種狀態(tài)
*
*
{@link #NEW} * ①未啟動的線程狀態(tài) new
* A thread that has not yet started is in this state.
*
*
{@link #RUNNABLE} * ②在jvm中執(zhí)行的線程狀態(tài) runnable
* A thread executing in the Java virtual machine is in this state.
*
*
{@link #BLOCKED} * ③一個線程被阻塞,等待監(jiān)控鎖的線程狀態(tài) blocked
* A thread that is blocked waiting for a monitor lock
* is in this state.
*
*
{@link #WAITING} * ④一個線程 為了永久等待另一個線程特定的操作的線程狀態(tài) waiting
* 翻譯后通順點:無限等待另一個線程的線程執(zhí)行特定的操作處于此狀態(tài)
* A thread that is waiting indefinitely for another thread to
* perform a particular action is in this state.
*
*
{@link #TIMED_WAITING} * ⑤ 一個線程 等待另一個線程執(zhí)行特定的操作的等待時間內(nèi)的線程狀態(tài) timed_waiting
* 正在等待另一個線程執(zhí)行某個操作的線程在指定的等待時間內(nèi)處于這種狀態(tài)
* A thread that is waiting for another thread to perform an action
* for up to a specified waiting time is in this state.
*
*
{@link #TERMINATED} * ⑥一個線程已經(jīng)被退出的狀態(tài) 終止 terminated
* A thread that has exited is in this state.
*
*
*
*
* 在給定的時間點上,線程只能處于一種狀態(tài)。這些狀態(tài)是虛擬機狀態(tài),不反映任何操作系統(tǒng)線程狀態(tài)
* 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:
*
*
{@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,
/**
* 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 state for a terminated thread.
* The thread has completed execution.
*/
TERMINATED;
}
```
到此,關(guān)于“JAVA線程一共有幾種狀態(tài)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
本文題目:JAVA線程一共有幾種狀態(tài)
文章起源:http://weahome.cn/article/gejgij.html