Thread Lifecycle:
Want to start the multithreaded programming? Before starting you need to know what is Thread and what is the life cycle of the Thread. Thread having different states and life cycle methods. To know about the thread you can Visit my last post Java Thread Example. Here we will talk about the life-cycle of the Thread.
Following are the states in the life cycle of the Threads :
New: When we initialize the new
thread using new operator, new
thread is created and state is
called New Thread. In this state
thread is not active or running.
Runnable: At the time when we
call Thread.start() method, state of
thread object changed to Runnable
and it's now on OS that it when or
how it will get CPU to run. In this
state the control is given to Thread
scheduler to finish its execution.
Running: Now when scheduler run
it then state is changed to Running.
Thread scheduler picks one of the
thread from runnable thread pool and
change it's state to Running and
thread getting executed.
Blocked/Waiting: When the thread
is waiting for another thread to
complete or free resource or any
user input then the thread is come
to waiting state. So once the thread
wait state is over, its again comes
to Runnable state.
Dead / Terminated: Once the
thread finished executing, its
state is changed to Dead. As soon as
the run() method exits the thread is
become dead or its terminated and no
longer alive.
0 Comment(s)