Thread lifecycle

摘选自《JAVA in a Nutshell》

 

A thread can be in one of six states. In Java 5.0, these states are represented by the THRead.State enumerated type, and the state of a thread can be queried with the getState( ) method. A listing of the Thread.State constants provides a good overview of the lifecycle of a thread:


 

NEW

The Thread has been created but its start( ) method has not yet been called. All threads start in this state.


RUNNABLE

The thread is running or is available to run when the operating system schedules it.


BLOCKED

The thread is not running because it is waiting to acquire a lock so that it can enter a synchronized method or block. We'll see more about synchronized methods and blocks later in this section.


WAITING

The thread is not running because it has called Object.wait() or Thread.join( ) .


TIMED_WAITING

The thread is not running because it has called Thread.sleep() or has called Object.wait( ) or Thread.join() with a timeout value.


TERMINATED

The thread has completed execution. Its run( ) method has exited normally or by throwing an exception .

你可能感兴趣的:(thread)