mvn -q -DskipTests exec:java "-Dexec.mainClass=edu.eci.arsw.pc.PCApp \
-Dmode=spin -Dproducers=1 -Dconsumers=1 -Dcapacity=8 -DprodDelayMs=50 -DconsDelayMs=1 -DdurationSec=30"mvn -q -DskipTests exec:java "-Dexec.mainClass=edu.eci.arsw.pc.PCApp \
-Dmode=monitor -Dproducers=1 -Dconsumers=1 -Dcapacity=8 -DprodDelayMs=50 -DconsDelayMs=1 -DdurationSec=30"- Slow producer / Fast consumer → consumer must wait without CPU when there are no elements.
- Fast producer / Slow consumer with stock limit → producer must wait without CPU when the queue is full (small capacity, e.g. 4 or 8).
- Visualize CPU with jVisualVM and compare
mode=spinvsmode=monitor.
| Aspect | BusySpinQueue (spin) |
BoundedBuffer (monitor) |
|---|---|---|
| CPU Usage | High (constant spinning) | Low (threads sleep when waiting) |
| Thread State | RUNNABLE (always) | WAITING/TIMED_WAITING (when idle) |
| Mechanism | while(true) + Thread.onSpinWait() |
synchronized + wait() + notifyAll() |
| Efficiency | ❌ Wastes CPU cycles | ✅ Releases CPU when blocked |
jVisualVM Monitor: High CPU usage with busy-wait
jVisualVM Threads: Threads in RUNNABLE state constantly

