package com.iluwatar.doublechecked.locking;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 
 * In {@link Inventory} we store the items with a given size. However, we do not store
 * more items than the inventory size. To address concurrent access problems we
 * use double checked locking to add item to inventory. In this method, the
 * thread which gets the lock first adds the item.
 * 
 */
public class App {

	/**
	 * Program entry point
	 * @param args command line args
	 */
	public static void main(String[] args) {
		final Inventory inventory = new Inventory(1000);
		ExecutorService executorService = Executors.newFixedThreadPool(3);
		for (int i = 0; i < 3; i++) {
			executorService.execute(new Runnable() {
				@Override
				public void run() {
					while (inventory.addItem(new Item()))
						;
				}
			});
		}
	}
}

@@ -131,16 +131,345 @@
 /**%0A * %0A
+ * Double Checked Locking is a concurrency design pattern used to reduce the overhead %0A * of acquiring a lock by first testing the locking criterion (the %22lock hint%22) without %0A * actually acquiring the lock. Only if the locking criterion check indicates that %0A * locking is required does the actual locking logic proceed.%0A * %3Cp%3E%0A
  * In %7B@

Improve Double Checked Locking Javadoc