Resolves checkstyle errors for delegation dependency-injection dirty-flag double-buffer double-checked-locking double-dispatch (#1068)
* Reduces checkstyle errors in delegation * Reduces checkstyle errors in dependency-injection * Reduces checkstyle errors in dirty-flag * Reduces checkstyle errors in double-buffer * Reduces checkstyle errors in double-checked-locking * Reduces checkstyle errors in double-dispatch
This commit is contained in:
		
				
					committed by
					
						 Ilkka Seppälä
						Ilkka Seppälä
					
				
			
			
				
	
			
			
			
						parent
						
							01e489c77b
						
					
				
				
					commit
					f2c91eb836
				
			| @@ -23,32 +23,30 @@ | ||||
|  | ||||
| package com.iluwatar.doublechecked.locking; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import java.util.concurrent.ExecutorService; | ||||
| import java.util.concurrent.Executors; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Double Checked Locking is a concurrency design pattern used to reduce the overhead of acquiring a | ||||
|  * lock by first testing the locking criterion (the "lock hint") without actually acquiring the | ||||
|  * lock. Only if the locking criterion check indicates that locking is required does the actual | ||||
|  * locking logic proceed. | ||||
|  * <p> | ||||
|  * 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. | ||||
|  *  | ||||
|  * | ||||
|  * <p>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 { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | ||||
|  | ||||
|   /** | ||||
|    * Program entry point | ||||
|    *  | ||||
|    * Program entry point. | ||||
|    * | ||||
|    * @param args command line args | ||||
|    */ | ||||
|   public static void main(String[] args) { | ||||
|   | ||||
| @@ -23,19 +23,16 @@ | ||||
|  | ||||
| package com.iluwatar.doublechecked.locking; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| import java.util.concurrent.locks.Lock; | ||||
| import java.util.concurrent.locks.ReentrantLock; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Inventory | ||||
|  * | ||||
|  * Inventory. | ||||
|  */ | ||||
| public class Inventory { | ||||
|  | ||||
| @@ -46,7 +43,7 @@ public class Inventory { | ||||
|   private final Lock lock; | ||||
|  | ||||
|   /** | ||||
|    * Constructor | ||||
|    * Constructor. | ||||
|    */ | ||||
|   public Inventory(int inventorySize) { | ||||
|     this.inventorySize = inventorySize; | ||||
| @@ -55,7 +52,7 @@ public class Inventory { | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Add item | ||||
|    * Add item. | ||||
|    */ | ||||
|   public boolean addItem(Item item) { | ||||
|     if (items.size() < inventorySize) { | ||||
| @@ -63,7 +60,8 @@ public class Inventory { | ||||
|       try { | ||||
|         if (items.size() < inventorySize) { | ||||
|           items.add(item); | ||||
|           LOGGER.info("{}: items.size()={}, inventorySize={}", Thread.currentThread(), items.size(), inventorySize); | ||||
|           LOGGER.info("{}: items.size()={}, inventorySize={}", Thread.currentThread(), items | ||||
|               .size(), inventorySize); | ||||
|           return true; | ||||
|         } | ||||
|       } finally { | ||||
| @@ -74,7 +72,7 @@ public class Inventory { | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Get all the items in the inventory | ||||
|    * Get all the items in the inventory. | ||||
|    * | ||||
|    * @return All the items of the inventory, as an unmodifiable list | ||||
|    */ | ||||
|   | ||||
| @@ -24,9 +24,7 @@ | ||||
| package com.iluwatar.doublechecked.locking; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Item | ||||
|  * | ||||
|  * Item. | ||||
|  */ | ||||
| public class Item { | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user