Loading
Thread Life Cycle

Q1. Explain the thread life cycle in Java.
In Java, a thread goes through multiple states during execution: New, Runnable, Running, Waiting, Timed Waiting, and Terminated. These states define how a thread is created, scheduled, paused, resumed, or destroyed.


Q2. What are the different states of a thread in Java with methods that cause transitions?
The main states are:
  • New – Created using Thread t = new Thread( ); but not started yet.
  • Runnable – After calling start( ), the thread becomes ready to run.
  • Running – When the CPU scheduler picks it, run( ) executes.
  • Waiting – wait( ) method makes a thread wait indefinitely.
  • Timed Waiting – sleep(ms), join(ms), or wait(ms) make the thread wait for a fixed time.
  • Terminated – After run( ) completes or an exception occurs.


Q3. What is the difference between start() and run() in the thread life cycle?
Calling start( ) creates a new thread and moves it to the Runnable state, eventually executing run( ). If you call run( ) directly, it executes like a normal method inside the same thread, without creating a new one.


Q4. How does a thread move from Waiting or Timed Waiting back to Runnable?
A thread in Waiting state resumes when another thread calls notify( ) or notifyAll( ). A thread in Timed Waiting automatically returns to Runnable after the specified time expires or if interrupted.


Q5. What is the final state of a thread, and can it be restarted?
The final state is Terminated (Dead), which means the thread’s run( ) has completed. A terminated thread cannot be restarted; if you try calling start( ) again, it throws an IllegalThreadStateException.