Lesson 26: Multithreading Basics: Thread & Runnable

27 Jul 2026 1 min Swarnil Singhai

Threads let independent tasks run concurrently — essential when one slow operation (like a network call) shouldn't block everything else.

Real-time example

A web crawler fetches 5 URLs in parallel threads instead of one after another, cutting total time roughly 5x.

Runnable fetchTask = () -> System.out.println(
    Thread.currentThread().getName() + " fetching URL...");

for (int i = 0; i < 3; i++) {
    new Thread(fetchTask, "worker-" + i).start();
}

What's happening

Each new Thread(...).start() runs concurrently with the main thread and with each other — order of output is not guaranteed.

Raw threads are rarely used directly in production code anymore — see the ExecutorService lesson for the real-world pattern.

Advertisement