Thread vs Runnable and the Thread Lifecycle

Difficulty: Beginner

Question

How do you create a thread in Java? Thread vs Runnable, start() vs run(), and what are the thread states?

Answer

Multithreading questions are a guaranteed part of Java interviews, and this is the entry point. Let me explain it like a kitchen: a thread is a cook, and a Runnable is the recipe card. Do you want to hire a special cook with the recipe tattooed on his arm, or keep the recipe separate so any cook can follow it? That is the whole Thread versus Runnable debate.

There are two classic ways to create a thread. First, extend the Thread class and override run. Second, implement the Runnable interface, which has a single method run, and pass the object to a Thread constructor. In modern code, you write the Runnable as a lambda: new Thread(() -> doWork()). There is a third option, Callable, which is like Runnable but returns a value and can throw checked exceptions; you submit it to an ExecutorService and get a Future.

Which should you prefer? Runnable, nearly always. Java has single inheritance, so extending Thread uses up your only superclass slot. Runnable separates the task (what to run) from the mechanism (how to run it), which lets you run the same task on a plain thread, a thread pool or a scheduled executor. Extending Thread is only justified if you actually want to change thread behaviour itself, which is rare.

Now the classic trap: start versus run. Calling start asks the JVM to create a new OS-level thread, and that new thread then executes run. Calling run directly is just an ordinary method call executing on the current thread; no new thread is created. That is why printing Thread.currentThread().getName() inside run shows main if you call run yourself. Also, calling start twice on the same thread throws IllegalThreadStateException, because a thread can only be started once.

The lifecycle has six states defined in Thread.State. NEW: created but start not called. RUNNABLE: ready or running (Java does not separate ready and running). BLOCKED: waiting to acquire a monitor lock to enter a synchronized block. WAITING: waiting indefinitely for another thread, after wait, join or LockSupport.park with no timeout. TIMED_WAITING: waiting with a timeout, such as sleep, wait(ms) or join(ms). TERMINATED: run has completed or ended with an exception.

Other essential methods. join makes the calling thread wait until the target thread finishes. sleep pauses the current thread without releasing any locks it holds. yield is a scheduler hint. interrupt sets the interrupt flag and wakes a thread from sleep or wait with InterruptedException; interruption is a cooperative cancellation mechanism, not a kill. The deprecated stop should never be used.

Also mention daemon threads. A daemon thread, set before start with setDaemon(true), does not keep the JVM alive; the JVM exits when only daemon threads remain. Garbage collector threads are daemons. The JVM's main thread and user threads are non-daemon.

Finally, for real applications you rarely create raw threads. Creating a thread per task is costly in memory and context switching, so use an ExecutorService thread pool. Since Java 21, virtual threads (Thread.ofVirtual or Executors.newVirtualThreadPerTaskExecutor) make thread-per-task cheap for blocking I/O workloads, and you can mention them as a modern answer.

Code examples

start() vs run()

public class ThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        Runnable task = () ->
            System.out.println("Running in " + Thread.currentThread().getName());

        Thread t = new Thread(task, "worker-1");
        t.run();
        t.start();
        t.join();

        System.out.println(t.getState());
        try {
            t.start();
        } catch (IllegalThreadStateException e) {
            System.out.println("cannot restart");
        }
    }
}

run executes on the main thread; start executes on the new worker-1 thread. After join the state is TERMINATED and a thread cannot be started again.

Key points

Common follow-up questions

Interview tips

Concepts covered

Thread, Runnable, Callable, start vs run, Thread Lifecycle

More Core Java & Collections questions