...
Code Block | ||
---|---|---|
| ||
class InventoryManager { private final AtomicInteger itemsInInventory = new AtomicInteger(100); public final void returnItem() { while (true) { int old = itemsInInventory.get(); if (old == Integer.MAX_VALUE) { throw new IllegalStateException("Out of bounds"); } int next = old + 1; // DecrementIncrement if (itemsInInventory.compareAndSet(old, next)) { break; } } // end while } // end removeItem() } |
...