182k views
2 votes
What is the life cycle of a Thread (Thread States)?

1) New, Runnable, Running, Blocked, Terminated
2) New, Running, Runnable, Blocked, Terminated
3) Runnable, New, Running, Blocked, Terminated
4) Runnable, New, Blocked, Running, Terminated

User Oramas
by
8.3k points

1 Answer

4 votes

Final answer:

The correct life cycle of a thread includes the following states: New, Runnable, Running, Blocked, and Terminated. A thread begins as New, is ready to run when Runnable, actually executes when Running, may block for resources, and ends in the Terminated state.

Step-by-step explanation:

The life cycle of a thread in programming includes several states. The correct sequence for these states is:

  1. New
  2. Runnable
  3. Running
  4. Blocked
  5. Terminated

When a thread is created, it's in the New state. The thread then moves to the Runnable state where it's ready to run and may be picked by the scheduler to run, at which point it enters the Running state. If the thread becomes inactive due to some I/O operations or by explicitly yielding control, it enters the Blocked state. After its run is completed, the thread moves into the Terminated state where it has finished execution and cannot be restarted.

User Jame
by
9.5k points