A thread state. A thread can be in one of the following states:
NEW
A thread that has not yet started is in this state.RUNNABLE
A thread executing in the Java virtual machine is in this state.BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.TERMINATED
A thread that has exited is in this state.
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.
-
NEW
public static final Thread.State NEW
Thread state for a thread which has not yet started.
-
RUNNABLE
public static final Thread.State RUNNABLE
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
public static final Thread.State 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 callingObject.wait
.
-
WAITING
public static final Thread.State WAITING
Thread state for a waiting thread. A thread is in the waiting state due to calling one of the following methods: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.
-
TIMED_WAITING
public static final Thread.State 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:Thread.sleep
Object.wait
with timeoutThread.join
with timeoutLockSupport.parkNanos
LockSupport.parkUntil
-
TERMINATED
public static final Thread.State TERMINATED
Thread state for a terminated thread. The thread has completed execution.
-
park
public static void park()
Disables the current thread for thread scheduling purposes unless the permit is available.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:
- Some other thread invokes
unpark
with the current thread as the target; or - Some other thread interrupts the current thread; or
- The call spuriously (that is, for no reason) returns.
This 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.
- Some other thread invokes
-
parkNanos
public static void parkNanos(long nanos)
Disables the current thread for thread scheduling purposes, for up to the specified waiting time, unless the permit is available.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:
- Some other thread invokes
unpark
with the current thread as the target; or - Some other thread interrupts the current thread; or
- The specified waiting time elapses; or
- The call spuriously (that is, for no reason) returns.
This 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.
- Parameters:
nanos
- the maximum number of nanoseconds to wait
- Some other thread invokes
-
parkUntil
public static void parkUntil(long deadline)
Disables the current thread for thread scheduling purposes, until the specified deadline, unless the permit is available.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:
- Some other thread invokes
unpark
with the current thread as the target; or - Some other thread interrupts the current thread; or
- The specified deadline passes; or
- The call spuriously (that is, for no reason) returns.
This 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.
- Parameters:
deadline
- the absolute time, in milliseconds from the Epoch, to wait until
- Some other thread invokes