A thread can be in one of the following states:
New thread. A thread is in this state after it has been created using the Thread constructor but before the start method has been invoked. A new thread will have no system resources allocated for it.
Runnable. A thread becomes runnable when the start method is invoked. This does not mean that a thread is actually running; in a single-processor computer system, another thread may be running at a given moment.
Not runnable. A thread cannot run. A thread becomes not runnable when the Thread class sleep or wait method has been invoked.
Dead. A thread dies when it stops. This occurs automatically when the thread's run method terminates.
Finally, the Thread class includes a method isAlive to test if a thread is alive. A thread is alive if it has been started and has not yet died. If a thread is alive, it is either runnable or not runnable. One cannot distinguish one state from the other. If a thread is not alive, it is either a new thread or dead. Again, it is not possible to distinguish between these states.
New thread. A thread is in this state after it has been created using the Thread constructor but before the start method has been invoked. A new thread will have no system resources allocated for it.
Runnable. A thread becomes runnable when the start method is invoked. This does not mean that a thread is actually running; in a single-processor computer system, another thread may be running at a given moment.
Not runnable. A thread cannot run. A thread becomes not runnable when the Thread class sleep or wait method has been invoked.
Dead. A thread dies when it stops. This occurs automatically when the thread's run method terminates.
Finally, the Thread class includes a method isAlive to test if a thread is alive. A thread is alive if it has been started and has not yet died. If a thread is alive, it is either runnable or not runnable. One cannot distinguish one state from the other. If a thread is not alive, it is either a new thread or dead. Again, it is not possible to distinguish between these states.
No comments:
Post a Comment