標籤:分享 同步代碼塊 tor nano ESS 圖片 other 啟動 對象
java.lang.Thread.State
成員內部類
NEW:還未啟動
Thread state for a thread which has not yet started.
RUNNABLE:正在jvm中運行,但是可能正在等待作業系統的其他資源
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.
BLOCKED:受阻塞,並且正在等待監視器鎖
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}.
WAITING:處於等待狀態的線程,正在等待另一個線程執行特定的操作
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.
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.
TIMED_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}
TERMINATED
Thread state for a terminated thread.
The thread has completed execution.
Thread start()
sleep() sleep(?)
join()
Object wait() notify() notifyAll()
wait(?)
建立(new)
可運行(Runnable)
阻塞(block)
死亡(dead)
新建立一個線程,線程處於建立狀態(new)
調用線程的start()方法,線程進入可運行狀態(Runnable),該線程位於可運行線程池中,等待被線程調度選中,擷取CPU使用權,此時線程處於就緒狀態
處於就緒狀態的線程一點獲得CPU使用權,進入運行狀態
一個線程在執行過程中,想獲得某一資源的鎖,但是該資源又被其它線程佔用,此時,當前線程處於阻塞狀態(例如,進入一個同步方法或者同步代碼塊,要先獲得鎖)
一個線程處於等待(waiting)狀態,表示該線程正在等待其它線程執行特定的操作
例如,一個線程調用了Object類的空參的wait方法,表示該線程等待其它線程調用該對象的notify或者notifyAll方法
一個線程調用了Thread類的空參的join方法,表示該線程在等待一個特定的線程終止
一個線程處於逾時等待狀態(timed_waiting),和waiting不同的是,將在特定的時間內自行返回
一個線程執行完畢,進入終止狀態(terminated)
Java線程狀態(Thread.State)