Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: removed synchronized keyword from Reentrant lock example

...

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

  public final synchronized void removeItem() {
    if(lock.tryLock()) {
      try {
        if (itemsInInventory <= MIN_INVENTORY) {
    	  throw new IllegalStateException("Under stocked");
    	}
    	itemsInInventory--;
      } finally {
        lock.unlock();
      }	
    }
  } // end removeItem()
} 

...