# decsis-eci/lab_busy_wait_vs_wait_notify architecture

> Architecture diagram of the GitHub repository decsis-eci/lab_busy_wait_vs_wait_notify, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/decsis-eci/lab_busy_wait_vs_wait_notify
- Repository: https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify

## Overview

##### Project Type and Purpose
- This is a small Java command-line benchmarking tool that demonstrates and contrasts two producer/consumer implementations:
- Busy-wait queue (high CPU usage)
- Monitor-based bounded buffer (efficient CPU usage)
- It’s not a full-stack app but an educational/concurrent tool to measure CPU behavior under different synchronization strategies.

a. PCApp (the Orchestrator)
- Entry point (main class)
- Parses CLI arguments (mode, producers, consumers, capacity, delays, duration)
- Instantiates the chosen buffer implementation and spins up Producer and Consumer threads
b. Buffer Interface / Abstraction
- Implicit boundary between PCApp and specific implementations
c. BoundedBuffer (Monitor-based)
- Implements the Buffer interface
- Uses wait()/notify() to block producers/consumers without busy-spinning
d. BusySpinQueue (Busy-wait)
- Implements the Buffer interface
- Producers/consumers spin in a tight loop checking capacity/emptiness
e. Producer
- Runs in its own thread
- Calls buffer.put() with a configurable delay
f. Consumer
- Runs in its own thread
- Calls buffer.take() with a configurable delay
g. External Monitoring (optional)
- jVisualVM or any JMX-based profiler
- Shows CPU usage under both modes

##### Relationships and Data Flow
- PCApp → (injects) → Buffer Interface
- Buffer Interface → (realizes) → BoundedBuffer or BusySpinQueue (depending on mode)
- PCApp → (creates & starts) → Producer threads → (call) → Buffer.put()
- PCApp → (creates & starts) → Consumer threads → (call) → Buffer.take()
- Producer/Consumer threads ⇄ Buffer implementations (synchronized access)
- PCApp → (optionally exposes) → JMX port → jVisualVM

##### Architectural Patterns and Principles
- Strategy Pattern: selecting between two Buffer implementations at runtime
- Dependency Injection: PCApp decouples thread logic from concrete implementation
- Thread-per-Role: separate thread classes for producer and consumer
- Monitor vs Busy-Spin illustrates trade-off: blocking vs CPU polling

##### Essential Elements
- Clear component names matching class names in your package:
- edu.eci.arsw.pc.PCApp
- edu.eci.arsw.pc.BoundedBuffer
- edu.eci.arsw.pc.BusySpinQueue
- edu.eci.arsw.pc.Producer
- edu.eci.arsw.pc.Consumer
- Ports or interfaces on the Buffer abstraction to indicate “put()/take()”
- A note or footnote calling out “mode=spin vs mode=monitor”

## Diagram (Mermaid)

```mermaid
flowchart TD
    PCApp["PCApp<br/>(edu.eci.arsw.pc.PCApp)<br/>CLI args"]:::orchestrator
    BufferInterface["IQueue<br/>put()/take()"]:::buffer
    BoundedBuffer["BoundedBuffer<br/>(monitor)"]:::buffer
    BusySpinQueue["BusySpinQueue<br/>(busy-wait)"]:::buffer
    Producer["Producer<br/>(delay)"]:::thread
    Consumer["Consumer<br/>(delay)"]:::thread
    pom["pom.xml<br/>(build config)"]:::external
    jVisualVM["jVisualVM<br/>(JMX profiler)"]:::external
    Note["mode=spin vs mode=monitor"]:::external

    PCApp -->|injects Buffer| BufferInterface
    BufferInterface -.->|realizes| BoundedBuffer
    BufferInterface -.->|realizes| BusySpinQueue
    PCApp -->|starts thread| Producer
    PCApp -->|starts thread| Consumer
    Producer -->|"put(item)"| BufferInterface
    Consumer -->|"take(item)"| BufferInterface
    PCApp -->|exposes JMX| jVisualVM
    PCApp -->|reads CLI args| pom

    click PCApp "https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify/blob/main/src/main/java/edu/eci/arsw/pc/PCApp.java"
    click BoundedBuffer "https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify/blob/main/src/main/java/edu/eci/arsw/pc/BoundedBuffer.java"
    click BusySpinQueue "https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify/blob/main/src/main/java/edu/eci/arsw/pc/BusySpinQueue.java"
    click Producer "https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify/blob/main/src/main/java/edu/eci/arsw/pc/Producer.java"
    click Consumer "https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify/blob/main/src/main/java/edu/eci/arsw/pc/Consumer.java"
    click pom "https://github.com/decsis-eci/lab_busy_wait_vs_wait_notify/blob/main/pom.xml"

    classDef orchestrator fill:#a8d0e6,stroke:#333,stroke-width:1px
    classDef buffer fill:#98e2a9,stroke:#333,stroke-width:1px
    classDef thread fill:#f7a35c,stroke:#333,stroke-width:1px
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px
```
