Java Thread Lifecycle States Explained

Thread Life Cycle in Java 1. NEW (Thread Created) 👉 Meaning: Thread object is created, but not started yet. Example: Thread t = new Thread(() -> { System.out.println("Running"); }); 📌 State: t.getState(); // NEW 2. RUNNABLE (Ready + Running) 👉 Meaning: Thread is ready to run and may be executing. ⚠️ In Java: RUNNING is part of RUNNABLE OS decides when it runs Example: t.start(); // Goes to RUNNABLE 📌 State: RUNNABLE 3. BLOCKED (Waiting for Lock) 👉 Meaning: Thread is waiting to acquire monitor lock. Example: synchronized(obj) { // other thread holds lock } If lock busy → BLOCKED. 4. WAITING (Waiting Indefinitely) 👉 Meaning: Thread waits until another thread wakes it. Caused by: wait() join() park() Example: obj.wait(); // WAITING 5. TIMED_WAITING (Waiting for Time) 👉 Meaning: Thread waits for a fixed time. Caused by: sleep(1000) wait(1000) join(1000) Example: Thread.sleep(1000); // TIMED_WAITING 6. TERMINATED (Dead) 👉 Meaning: Thread finished execution. Example: run() ends → TERMINATED #Java #Multithreading #interview #sde #interviewpreparation #ThreadLifecycle

To view or add a comment, sign in

Explore content categories