Thread States :
New: This is the state the thread is in after the Thread instance has been created, but the start() method has not been invoked on the thread. It is a live Thread object, but not yet a thread of execution. At this point, the thread is considered not alive
Runnable: This is the state a thread is in when it's eligible to run, but the scheduler has not selected it to be the running thread. A thread first enters the runnable state when the start() method is invoked, but a thread can also return to the runnable state after either running or coming back from a blocked, waiting, or sleeping state. When the thread is in the runnable state,it is considered alive.
Running: This is it. The "big time." Where the action is. This is the state a thread is in when the thread scheduler selects it (from the runnable pool) to be the currently executing process.
Waiting/blocked/sleeping: This is the state a thread is in when it's not eligible to run. Okay, so this is really three states combined into one, but they all have one thing in common: the thread is still alive, but is currently not eligible to run.
Some methods may look like they tell another thread to block, but they don't. If you have a reference t to another thread, you can write something like this
t.sleep(); or t.yield()
But those are actually static methods of the Thread class—they don't affect the instance t; instead they are defined to always affect the thread that's currently executing.
Dead: A thread is considered dead when its run() method completes. It may still be a viable Thread object, but it is no longer a separate thread of execution. Once a thread is dead, it can never be brought back to life! If you invoke start() on a dead Thread
instance, you'll get a runtime (not compiler) exception.
No comments:
Post a Comment