GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction
  • Multiprocessing vs. Multithreading
  • Process vs. Thread
  • Java Thread Model

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Java Multithreading Tutorial - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

Java Multithreading Tutorial

Last Updated : 31 Mar, 2026

Multithreading in Java is a feature that allows multiple tasks to run concurrently within the same program. Instead of executing one task at a time, Java enables parallel execution using lightweight threads. This makes applications more efficient, faster and responsive in real-world scenarios like servers, games and chat systems.

Key Features of Multithreading

  • A thread is the smallest unit of execution in Java.
  • Threads share the same memory space but run independently.
  • Java provides the Thread class and Runnable interface to create threads.
  • Multithreading ensures better CPU utilization by executing tasks simultaneously.
  • Synchronization is needed to prevent data inconsistency when threads share resources.

Example: Suppose a restaurant kitchen where multiple chefs are working simultaneously on different dishes. This setup ensures faster service and better CPU (chef) utilization, just like threads in Java.

Example: Java Program to illustrate Creation and execution of a thread via start() and run() method in Single inheritance

Java
class MyThread1 extends Thread {

    public void run()
    {
        System.out.println("Thread1 is running");
    }
}

class MyThread2 extends Thread {

    public void run()
    {
        System.out.println("Thread2 is running");
    }
}

class GFG {

    public static void main(String[] args)
    {
        MyThread1 obj1 = new MyThread1();
        MyThread2 obj2 = new MyThread2();
        obj1.start();
        obj2.start();
    }
}

Output
Thread1 is running
Thread2 is running

Introduction to Multithreading

Multithreading allows concurrent execution of two or more parts of a program for maximum CPU usage. It improves application performance and responsiveness.

  • Introduction
  • Multiprocessing vs. Multithreading

Processes vs Threads

A process is an independent program in execution, while a thread is a lightweight sub-process. Understanding their differences is key to mastering concurrency.

  • Process vs. Thread
  • Java Thread Model

Thread Class and Runnable Interface

In Java, threads can be created either by extending the Thread class or by implementing the Runnable interface. Both approaches have different use cases.

  • Thread Class
  • Runnable Interface
  • Create a Thread

Thread Lifecycle

A thread passes through different states like New, Runnable, Running, Waiting and Terminated. The lifecycle is managed by the JVM and thread scheduler.

  • Lifecycle and States
  • Thread Scheduler

Thread Methods

Java provides built-in methods like start(), run(), sleep() and join() to manage thread execution and control its behavior.

  • start() Method
  • suspend() Method
  • stop() Method
  • sleep() Method
  • join() Method

Thread Priorities

Threads can be assigned priorities to influence scheduling decisions. Higher priority threads are given preference by the thread scheduler.

  • Introduction
  • setName()
  • getName()

Synchronization

Synchronization ensures that multiple threads do not interfere with each other while accessing shared resources. It helps prevent data inconsistency and race conditions.

  • Introduction
  • Importance of Thread Synchronization
  • Synchronized methods & synchronized blocks
  • Static synchronization
  • object level lock
  • class level lock

Inter-thread Communication

Threads can communicate using methods like wait(), notify() and notifyAll(). This enables coordination between multiple threads.

  • Introduction
  • wait()
  • notify() and notifyAll()

Deadlock

Deadlock occurs when two or more threads wait indefinitely for resources locked by each other. Java provides techniques to avoid and resolve deadlocks.

  • Introduction
  • Deadlock example and prevention techniques

Thread Safety

Thread safety ensures correct program execution when multiple threads access shared data. Techniques include synchronized, volatile and ThreadLocal.

  • Using Synchronization
  • Using Volatile Keyword
  • Using Atomic Variable
  • Using Final Keyword

Daemon Threads

Daemon threads are background threads that run to support user threads and automatically terminate when all user threads finish execution.

  • User vs Daemon Thread
  • setDaemon()

Concurrency Utilities (java.util.concurrent)

The concurrency package provides tools like Executors, Callable, Future and Thread Pools. These simplify managing multithreaded applications.

  • Introduction
  • Callable and Future
  • Thread Pools
  • ScheduledExecutorService
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.