|
| |

- When a thread is first created, it enters the NEW
state, at which point it is not executing
- When the thread's start()
method is invoked, the thread changes to the RUNNABLE
state.
- When the thread is RUNNABLE, it is eligible
for execution, but not necessarily running.
- When certain events happen to a RUNNABLE thread, it
may enter the NOT RUNNABLE state, where it is still
alive, but not eligible for execution. Such events
include:
- Thread is waiting for an I/O operation to
complete
- Thread has put itself to sleep for a certain
period of time (by calling sleep())
- Thread has called wait()
- Thread has called yield()
- A NOT RUNNABLE thread becomes RUNNABLE again when the
condition that caused the thread to become NOT
RUNNABLE ends:
- I/O completes
- Sleep period expires
- etc.
- When the thread terminates, it becomes DEAD --
permanently! Once the thread enters the DEAD state,
there is no way to resuscitate it. There are a number
of ways a thread may terminate, including:
- By returning from its run() method (this
is the recommended approach)
- By being stopped (dangerous! -- don't do it!)
|