The Concurrency Showcase project demonstrates various Java concurrency tools and techniques through simple, self-contained examples. It is designed to highlight the capabilities of Java’s concurrency API, including both traditional and modern approaches.
Each demo provides an implementation of a specific concurrency mechanism, showcasing its purpose, usage, and behavior.
Here is the list of demos included in the project:
- Thread Management Demo: Basic thread creation and management.
- Virtual Threads Demo: Demonstrates Java’s lightweight virtual threads (requires JDK 21+).
- Structured Concurrency Demo: Uses the structured concurrency API to manage task lifecycles (preview feature).
- Structured Concurrency Legacy Demo: Legacy approach to structured concurrency without preview features.
- BlockingQueue Demo: Producer-consumer problem using a blocking queue.
- AtomicInteger Demo: Thread-safe counter implementation with
AtomicInteger. - ReentrantLock Demo: Shows the use of
ReentrantLockfor fine-grained locking. - CompletableFuture Demo: Demonstrates asynchronous programming with
CompletableFuture. - Parallel Streams Demo: Processing data in parallel using Java Streams.
- Semaphore Demo: Controls access to a resource using
Semaphore. - CyclicBarrier Demo: Synchronizes threads at a barrier point.
- Phaser Demo: Advanced synchronization with multiple phases.
- Fork/Join Framework Demo: Parallel task execution using the Fork/Join framework.
- Exchanger Demo: Exchange data between producer-consumer pairs, including a streaming implementation.
- Java: JDK 21 or higher (for virtual threads and preview features).
- Gradle: Installed and configured for project build.
-
Clone the repository:
git clone https://github.com/LionH/ConcurrencyShowcase.git cd ConcurrencyShowcase -
Build the project:
./gradlew build
-
Run the application:
./gradlew run
-
Follow the menu prompts to select and run a specific demo.
ConcurrencyShowcase/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── io/github/lionh/concurrency/demo/
│ │ │ ├── ThreadDemo.java
│ │ │ ├── VirtualThreadsDemo.java
│ │ │ ├── StructuredConcurrencyDemo.java
│ │ │ ├── StructuredConcurrencyLegacyDemo.java
│ │ │ ├── BlockingQueueDemo.java
│ │ │ ├── AtomicIntegerDemo.java
│ │ │ ├── ReentrantLockDemo.java
│ │ │ ├── CompletableFutureDemo.java
│ │ │ ├── ParallelStreamsDemo.java
│ │ │ ├── SemaphoreDemo.java
│ │ │ ├── CyclicBarrierDemo.java
│ │ │ ├── PhaserDemo.java
│ │ │ ├── ForkJoinDemo.java
│ │ │ └── ExchangerDemo.java
├── build.gradle.kts
└── README.md
Contributions are welcome! If you have ideas for additional demos or improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.