Skip to content

Hands-on Java concurrency playground covering core java.util.concurrent concepts with runnable examples.

Notifications You must be signed in to change notification settings

eiabhiram/java-concurrency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧡 Java Concurrency Playground

This repository is a pure Java learning project created to understand and experiment with the core concepts of Java concurrency using the java.util.concurrent package.

Each concurrency concept is implemented as a separate Java class with its own main() method, making it easy to run, observe, and modify behavior independently.

πŸ“š Reference
This project is based on and inspired by Baeldung’s excellent guide:
https://www.baeldung.com/java-util-concurrent


🎯 Objectives

  • Understand why Java concurrency utilities exist
  • Learn how different concurrency tools behave
  • Observe real multithreaded execution
  • Build a strong foundation before moving to:
    • CompletableFuture
    • Reactive programming
    • Virtual Threads (Java 21+)

πŸ—‚ Project Structure

com.example.concurrency
 β”œβ”€β”€ ExecutorDemo.java
 β”œβ”€β”€ ExecutorServiceDemo.java
 β”œβ”€β”€ ScheduledExecutorDemo.java
 β”œβ”€β”€ FutureDemo.java
 β”œβ”€β”€ CountDownLatchDemo.java
 β”œβ”€β”€ CyclicBarrierDemo.java
 β”œβ”€β”€ SemaphoreDemo.java
 β”œβ”€β”€ ThreadFactoryDemo.java
 β”œβ”€β”€ BlockingQueueDemo.java
 β”œβ”€β”€ DelayQueueDemo.java
 β”œβ”€β”€ LockDemo.java
 └── PhaserDemo.java

πŸ”Ή 2.1 Executor

Executor represents a strategy for executing tasks.
It does not guarantee asynchronous execution.

Key takeaway:

Decouples task submission from execution strategy.


πŸ”Ή 2.2 ExecutorService

Provides a complete asynchronous execution framework with thread pooling and lifecycle management.

Key takeaway:

Backbone of async execution in Java.


πŸ”Ή 2.3 ScheduledExecutorService

Used for delayed and periodic tasks such as polling and heartbeats.


πŸ”Ή 2.4 Future

Represents the result of an asynchronous computation.

Limitation: blocking-only (get()).


πŸ”Ή 2.5 CountDownLatch

Allows one or more threads to wait until N operations complete.

Mental model:

Wait until all tasks finish.


πŸ”Ή 2.6 CyclicBarrier

Allows multiple threads to wait for each other at a common point.

Mental model:

All workers must arrive before proceeding.


πŸ”Ή 2.7 Semaphore

Controls how many threads access a resource simultaneously.


πŸ”Ή 2.8 ThreadFactory

Customizes thread creation (naming, daemon status, handlers).


πŸ”Ή 2.9 BlockingQueue

Designed for producer–consumer scenarios with built-in blocking.


πŸ”Ή 2.10 DelayQueue

Elements become available only after a delay expires.


πŸ”Ή 2.11 Lock (ReentrantLock)

Explicit locking with more control than synchronized.


πŸ”Ή 2.12 Phaser

Advanced synchronization barrier supporting:

  • Multiple phases
  • Dynamic registration
  • Reusability

▢️ How to Run

Each class contains a main() method.

javac ClassName.java
java com.example.concurrency.ClassName

πŸ“š Reference

https://www.baeldung.com/java-util-concurrent


βœ… Final Note

This project focuses on understanding:

  • why concurrency tools exist
  • what problems they solve
  • when to use which

Building this intuition is key to mastering Java concurrency.

About

Hands-on Java concurrency playground covering core java.util.concurrent concepts with runnable examples.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages