标签:
A thread state. A thread can be in one of the following states:
NEW
RUNNABLE
BLOCKED
WAITING
TIMED_WAITING
TERMINATED
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.
public static final Thread.State NEW
public static final Thread.State RUNNABLE
public static final Thread.State BLOCKED
Object.wait
.public static final Thread.State WAITING
Object.wait
with no timeoutThread.join
with no timeoutLockSupport.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 calledThread.join() is waiting for a specified thread to terminate.
public static final Thread.State TIMED_WAITING
Thread.sleep
Object.wait
with timeoutThread.join
with timeoutLockSupport.parkNanos
LockSupport.parkUntil
public static final Thread.State TERMINATED
public static void park()
If the permit is available then it is consumed and the call returns immediately; otherwise the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
unpark
with the current thread as the target; orThis method does not report which of these caused the method to return. Callers should re-check the conditions which caused the thread to park in the first place. Callers may also determine, for example, the interrupt status of the thread upon return.
public static void parkNanos(long nanos)
If the permit is available then it is consumed and the call returns immediately; otherwise the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
unpark
with the current thread as the target; orThis method does not report which of these caused the method to return. Callers should re-check the conditions which caused the thread to park in the first place. Callers may also determine, for example, the interrupt status of the thread, or the elapsed time upon return.
nanos
- the maximum number of nanoseconds to waitpublic static void parkUntil(long deadline)
If the permit is available then it is consumed and the call returns immediately; otherwise the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
unpark
with the current thread as the target; orThis method does not report which of these caused the method to return. Callers should re-check the conditions which caused the thread to park in the first place. Callers may also determine, for example, the interrupt status of the thread, or the current time upon return.
deadline
- the absolute time, in milliseconds from the Epoch, to wait until标签:
原文地址:http://www.cnblogs.com/hushaojun/p/4875064.html