Back to Lessons

Multithreading and Concurrency

April 5, 2026

Java Multithreading

Execute multiple threads concurrently for better performance.

Thread Creation

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread running");
    }
}

class MyRunnable implements Runnable {
    public void run() {
        System.out.println("Runnable executing");
    }
}

// Usage
MyThread t1 = new MyThread();
t1.start();

Thread t2 = new Thread(new MyRunnable());
t2.start();

Key Points

  • Extend Thread or implement Runnable.
  • start() not run() to create new thread.
  • Runnable preferred (single inheritance).
  • Thread lifecycle: New, Runnable, Running, Blocked, Dead.