#107 Double Checked Locking example JavaDoc
This commit is contained in:
parent
e71f2279f0
commit
57e702db4f
@ -5,13 +5,18 @@ import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
*
|
||||
* In Inventory we store the items with a given size. However, we do not store
|
||||
* 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);
|
||||
|
@ -5,6 +5,11 @@ import java.util.List;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
*
|
||||
* Inventory
|
||||
*
|
||||
*/
|
||||
public class Inventory {
|
||||
|
||||
private int inventorySize;
|
||||
|
@ -1,6 +1,12 @@
|
||||
package com.iluwatar.doublechecked.locking;
|
||||
|
||||
/**
|
||||
*
|
||||
* Item
|
||||
*
|
||||
*/
|
||||
public class Item {
|
||||
String name;
|
||||
int level;
|
||||
|
||||
private String name;
|
||||
private int level;
|
||||
}
|
||||
|
@ -4,6 +4,11 @@ import org.junit.Test;
|
||||
|
||||
import com.iluwatar.doublechecked.locking.App;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user