Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: changed method from private to public

...

Code Block
bgColor#ccccff
class InventoryManager {
  private static final int MIN_INVENTORY = 3;
  private final AtomicInteger itemsInInventory = new AtomicInteger(100);

  privatepublic final void removeItem() {
    for (;;) {
      int old = itemsInInventory.get();
      if (old > MIN_INVENTORY) {
        int next = old - 1; // Decrement
        if(itemsInInventory.compareAndSet(old, next)) {
          break;
        }
      } else {
        throw new IllegalStateException("Under stocked");
      }
    } // end for
  } // end removeItem()
} 

...