A thread goes through various stages in its life cycle.
e.g, a thread is born, started, runs, and then dies.
life cycle of a thread
New
A new thread begins its life cycle in the new state. It
remains in this state until the program starts the thread. It
is also referred to as a born thread.
Runnable
After a newly born thread is started, the thread becomes
runnable. A thread in this state is considered to be
executing its task.
Waiting
Sometimes, a thread transitions to the waiting state while
the thread waits for another thread to perform a task.
A thread transitions back to the runnable state only when
another thread signals the waiting thread to continue
executing.
Timed waiting
A runnable thread can enter the timed waiting state for a
specified interval of time.
A thread in this state transitions back to the runnable state
when that time interval expires or when the event it is
waiting for occurs.
Terminated
A runnable thread enters the terminated state when it
completes its task or otherwise terminates.
Object.wait method
When a thread calls Object.wait method, it releases all
the acquired monitors and is put into WAITING or
TIMED_WAITING.
Now when the thread is notified either by notify( ) or
by notifyAll ( ) call on the same object then the waiting
state of the thread ends and the thread starts attempting
to regain all the monitors which it had acquired at the
time of wait call.
BLOCKED state
At one time there may be several threads trying to regain
their monitors.
If more than one threads attempt to acquire the monitor
of a particular object then only one thread is granted the
monitor and all other threads are put into BLOCKED
state.

Life cycle-of-a-thread

  • 1.
    A thread goesthrough various stages in its life cycle. e.g, a thread is born, started, runs, and then dies.
  • 2.
    life cycle ofa thread
  • 3.
    New A new threadbegins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread.
  • 4.
    Runnable After a newlyborn thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task.
  • 5.
    Waiting Sometimes, a threadtransitions to the waiting state while the thread waits for another thread to perform a task. A thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing.
  • 6.
    Timed waiting A runnablethread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs.
  • 7.
    Terminated A runnable threadenters the terminated state when it completes its task or otherwise terminates.
  • 8.
    Object.wait method When athread calls Object.wait method, it releases all the acquired monitors and is put into WAITING or TIMED_WAITING. Now when the thread is notified either by notify( ) or by notifyAll ( ) call on the same object then the waiting state of the thread ends and the thread starts attempting to regain all the monitors which it had acquired at the time of wait call.
  • 9.
    BLOCKED state At onetime there may be several threads trying to regain their monitors. If more than one threads attempt to acquire the monitor of a particular object then only one thread is granted the monitor and all other threads are put into BLOCKED state.