线程的状态 Thread.State||NEW,RUNNABLE,BLOCKED,WAITING,TIMED_WAITING,TERMINATED
生活随笔
收集整理的這篇文章主要介紹了
线程的状态 Thread.State||NEW,RUNNABLE,BLOCKED,WAITING,TIMED_WAITING,TERMINATED
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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;(終結)
}
wait 和Sleep功能都是當前線程暫停,有什么區別?
wait 和Sleep功能都是當前線程暫停,有什么區別?
? ? ? ? wait放開手去睡,放開手里的鎖
? ? ? ? sleep握緊手去睡,醒了手里還有鎖
總結
以上是生活随笔為你收集整理的线程的状态 Thread.State||NEW,RUNNABLE,BLOCKED,WAITING,TIMED_WAITING,TERMINATED的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 题目:三个售票员 卖出 30张票
- 下一篇: lambda表达式的使用 || Lamb