Skip to content

Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part of such program is called a thread. So, threads are light-weight processes within a process.

Notifications You must be signed in to change notification settings

Shubh2-0/Multi-Threading

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧵 Java Multi-Threading

GitHub stars GitHub forks GitHub issues

Multi-Threading

Master Concurrent Programming in Java

Maximize CPU utilization with threads, synchronization, and parallel execution

Concepts · Examples · Get Started


📖 Table of Contents


🎯 About

Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum CPU utilization. This repository covers everything from thread basics to advanced synchronization techniques.

Why Multithreading?

  • Performance - Utilize multiple CPU cores
  • 🔄 Responsiveness - Keep UI responsive during heavy tasks
  • 📊 Efficiency - Better resource utilization
  • 🎯 Parallelism - Execute multiple tasks simultaneously

💡 Concepts

Concept Description
Thread Lightweight process, smallest unit of execution
Runnable Interface for creating threads
Synchronized Prevent race conditions
Deadlock Circular wait condition
Thread Pool Reusable thread collection
Executor Framework for thread management

🔄 Thread Lifecycle

                    ┌─────────────────────────────────────────┐
                    │                                         │
                    ▼                                         │
┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐ │
│   NEW    │───►│ RUNNABLE │───►│ RUNNING  │───►│TERMINATED│ │
└──────────┘    └──────────┘    └────┬─────┘    └──────────┘ │
     │              ▲                │                        │
     │              │                ▼                        │
     │              │         ┌──────────┐                    │
     │              └─────────│ BLOCKED/ │                    │
     │                        │ WAITING  │                    │
     │                        └──────────┘                    │
     │                                                        │
     └────────────────────────────────────────────────────────┘

📚 Examples

Creating Threads

// Method 1: Extending Thread class
class MyThread extends Thread {
    public void run() {
        System.out.println("Thread running: " + getName());
    }
}

// Method 2: Implementing Runnable
class MyRunnable implements Runnable {
    public void run() {
        System.out.println("Runnable running");
    }
}

// Method 3: Lambda Expression (Java 8+)
Thread t = new Thread(() -> System.out.println("Lambda thread"));

Synchronization

class Counter {
    private int count = 0;
    
    public synchronized void increment() {
        count++;
    }
    
    public int getCount() {
        return count;
    }
}

🛠️ Technologies

Technology Purpose
Java 8+
Eclipse IDE
IntelliJ IDEA

🚀 Getting Started

# Clone the repository
git clone https://github.com/Shubh2-0/Multi-Threading.git
cd Multi-Threading

# Open in your IDE
# Run the examples and experiment!

📬 Contact

Shubham Bhati - Java Developer

LinkedIn Gmail WhatsApp


⭐ Star this repository to support multithreading learning!

Keywords: Java Multithreading Concurrency Thread Synchronization Deadlock Runnable Executor Thread-Pool Parallel-Programming

About

Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part of such program is called a thread. So, threads are light-weight processes within a process.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages