Nearby lessons
68 of 125Java - Thread Life Cycle
📌 What You Will Learn
- What a thread is and how it is different from a process
- Two ways to create a thread: Thread class and Runnable interface
- The thread life cycle (states)
- How threads cooperate: synchronized, wait and notify
- The modern way: Executors, Callable and lambdas
Thread Life Cycle is a core concept of the Java language. This lesson explains Thread Life Cycle — The States and Thread States — The Full Life Cycle with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Thread Life Cycle — The States
A thread travels through states during its life:
| State | Meaning |
|---|---|
| NEW | Thread object created, start() not yet called |
| RUNNABLE | start() called; thread is ready to run or running |
| BLOCKED | Waiting for a lock so it can enter a synchronized block |
| WAITING | Waiting for another thread to notify it |
| TIMED_WAITING | Waiting for a fixed time (sleep, join) |
| TERMINATED | run() finished; thread is dead |
Example01
Thread States — The Full Life Cycle
The classic material lists the thread states like this (modern Java names them slightly differently, but the ideas are the same):
| State | Meaning |
|---|---|
| NEW | Thread object created; start() not yet called |
| RUNNABLE | Ready to run or currently running |
| BLOCKED / WAITING | Waiting for a lock, or waiting to be notified |
| TIMED_WAITING | Waiting for a fixed time (sleep/join with timeout) |
| TERMINATED | run() finished; the thread is dead |
Example02
📝 Key Takeaways
- A thread is a small unit of work; a process is a running program.
- Create a thread by extending Thread or (better) implementing Runnable.
- Life cycle: NEW -> RUNNABLE -> BLOCKED/WAITING/TIMED_WAITING -> TERMINATED.
- Shared data races when many threads change it; synchronized gives a lock.
- wait/notify let threads talk; they need the lock.
- Deadlock = threads waiting on each other's locks; avoid by consistent lock order.
- Real projects use Executors + Callable instead of raw threads.
🧠 Test Your Knowledge
1 QuestionsProgress: 0 / 1