ProLesson 9.2Intermediate3 min readUpdated 30 October 2026
Creating threads and the thread life cycle
Start threads with Runnable, wait for them with join, name them, and learn the six thread states every interviewer asks about.
Let's start real threads. In everyday code you'll mostly use thread pools (lesson 9.7), but understanding raw threads makes everything else clear.
01Creating and starting a thread
The usual way is to give a Thread a Runnable, the task to run. A lambda works well:
StartThread.java
public class StartThread {
public static void main(String[] args) throws InterruptedException {
Runnable task = () -> System.out.println("Hello from " + Thread.currentThread().getName());
Thread worker = new Thread(task, "worker-1");
worker.start(); // runs task on a NEW thread
worker.join(); // wait for it to finish
System.out.println("Back in " + Thread.currentThread().getName());
}
}Hello from worker-1 Back in main
Loading the rest of the lesson…