How decsis-eci/lab_busy_wait_vs_wait_notify works
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”