Thread Life Cycle in Java — Java Technical Interview Questions & Answers
Thread Life Cycle in Java
Thread Life Cycle in Java
- A thread goes through states: New (created) → Runnable (start() called, waiting for CPU) → Running (CPU is executing it) → Blocked/Waiting (sleep, join, lock) → Terminated (finished).
- You cannot restart a terminated thread. start() only from New. Calling start() twice throws IllegalThreadStateException.
- Draw the states in viva. Don’t invent extra states.
- Let's take this on the board with one tiny Main class — no extra files. Thread Life Cycle in Java — start() schedules the thread; main also prints — order may vary. Start from main, go line by line, and stop at each print. That output is the proof for Thread Life Cycle.
New --start()--> Runnable
│ CPU
▼
Running
/ \
sleep/join done
│ │
▼ ▼
Waiting TerminatedTechnical Interview Tip: Draw five states. Say start() only once. Cannot restart a dead thread.
Code Examples for Thread Life Cycle in Java
Example
// Thread demo
public class Main {
public static void main(String[] args) {
Thread t = new Thread(() -> System.out.println("Hi from thread"));
t.start();
System.out.println("Hi from main");
}
}Thread Life Cycle in Java — start() schedules the thread; main also prints — order may vary.
How to Explain Thread Life Cycle in Java to an Interviewer
Name the thread states.
New Runnable Running Waiting/Blocked Terminated
Can you start a thread twice?
No IllegalThreadStateException