All my learnings, notes, and implementations around Multithreading & Concurrency in Java 🚀
This repository is a comprehensive collection of my explorations and hands-on implementations of multithreading and concurrency concepts in Java. It includes code samples, theoretical notes, best practices, common pitfalls, and advanced topics.
Whether you are a beginner or brushing up on concurrency, you'll find practical examples and explanations here!
- Core Multithreading Concepts
- Executor Service
- Practice Questions
- Concurrent Collections
- Thread Synchronization Demos
- Build & Run Instructions
- Contributing & License
Explore the fundamental building blocks of multithreading in Java, including thread creation, coordination, computation, and thread properties.
- Creating Threads
ExtendsThreadClass.java: Creating threads by extending theThreadclass.RunnableThreadExample.java: Implementing threads using theRunnableinterface.
- Thread Coordination
JoinThreadExample.java: Usingjoin()for thread coordination.WaitAndNotify.java: Inter-thread communication usingwait()andnotify().ProducerConsumer.java: Classic producer-consumer problem demo.
- Thread Priorities & Daemon Threads
ThreadPriority.java: Working with thread priorities.DaemonUser.java: Demonstrating daemon threads.
- Computation with Threads
AdderSubtractor.java: Performing arithmetic with threads.PrimeNumberUsingThreads.java: Calculating primes using threads.
Learn how to manage thread pools and advanced asynchronous tasks using Java's ExecutorService framework.
FixedThreadPoolDemo.java: Using a fixed thread pool.CachedThreadPoolDemo.java: Using a cached thread pool.SingleThreadExecutor.java: Single-threaded executor.ScheduledExecutorDemo.java: Scheduling tasks.CallableDemo.java: Using Callable and Future for async computation.CPU_IntensiveTask.java: Handling CPU-intensive tasks.CountSum100.java: Summation tasks with thread pools.
Browse all ExecutorService examples »
Sharpen your skills with hands-on problems and coding exercises related to thread communication and synchronization.
OddEven.java: Odd/even number threading problem.Print1to10.java: Printing numbers with threads.ProducerConsumer.java: Producer-consumer exercise.SumTo100.java: Summing numbers using threads.ThreadABC.java: Ordered execution of threads A, B, C.
Discover how to use thread-safe collections and synchronization mechanisms for managing shared resources.
BlockingQueueDemo.java: UsingBlockingQueuefor producer-consumer scenarios.CountDown.java: Synchronization with CountDownLatch/related constructs.SynchronizedCollection.java: Using synchronized collections in Java.
All concurrent collection demos »
Explore different synchronization techniques and locking mechanisms.
LockWithCustomVar.java: Custom lock implementation.PrintNums1to100.java: Synchronized number printing.SynchronizationDemo.java: Demonstration of basic synchronization.
Browse thread synchronization demos »
To browse or run the code examples:
- Clone this repository:
git clone https://github.com/Dibyo10/Multithreading_Concurrency_Learning.git
- Open in your favorite Java IDE (IntelliJ IDEA, Eclipse, VSCode, etc.).
- Run the example files as standard Java applications.
- Each directory contains self-contained Java files with a
mainmethod. - Compile and run with:
javac path/to/File.java java path.to.File
- Or run directly from your IDE.
- Official Java Concurrency Documentation
- Java Concurrency in Practice
- Baeldung - Guide to Java Concurrency
Contributions, suggestions, and doubts are welcome!
Feel free to open issues or pull requests.