Skip to content

LionH/ConcurrencyShowcase

Repository files navigation

Concurrency Showcase

Overview

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.


List of Demos

Here is the list of demos included in the project:

  1. Thread Management Demo: Basic thread creation and management.
  2. Virtual Threads Demo: Demonstrates Java’s lightweight virtual threads (requires JDK 21+).
  3. Structured Concurrency Demo: Uses the structured concurrency API to manage task lifecycles (preview feature).
  4. Structured Concurrency Legacy Demo: Legacy approach to structured concurrency without preview features.
  5. BlockingQueue Demo: Producer-consumer problem using a blocking queue.
  6. AtomicInteger Demo: Thread-safe counter implementation with AtomicInteger.
  7. ReentrantLock Demo: Shows the use of ReentrantLock for fine-grained locking.
  8. CompletableFuture Demo: Demonstrates asynchronous programming with CompletableFuture.
  9. Parallel Streams Demo: Processing data in parallel using Java Streams.
  10. Semaphore Demo: Controls access to a resource using Semaphore.
  11. CyclicBarrier Demo: Synchronizes threads at a barrier point.
  12. Phaser Demo: Advanced synchronization with multiple phases.
  13. Fork/Join Framework Demo: Parallel task execution using the Fork/Join framework.
  14. Exchanger Demo: Exchange data between producer-consumer pairs, including a streaming implementation.

Prerequisites

  • Java: JDK 21 or higher (for virtual threads and preview features).
  • Gradle: Installed and configured for project build.

How to Run

  1. Clone the repository:

    git clone https://github.com/LionH/ConcurrencyShowcase.git
    cd ConcurrencyShowcase
  2. Build the project:

    ./gradlew build
  3. Run the application:

    ./gradlew run
  4. Follow the menu prompts to select and run a specific demo.


Project Structure

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

Contributing

Contributions are welcome! If you have ideas for additional demos or improvements, feel free to open an issue or submit a pull request.


License

This project is licensed under the MIT License. See the LICENSE file for details.

About

showcase of concurrency using plain java 21

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published