Java 11 migrate c-d (remaining) (#1111)

* Moves converter pattern to Java 11

* Moves cqrs pattern to Java 11

* Moves dao pattern to Java 11

* Moves data-bus pattern to Java 11

* Moves data-locality pattern to Java 11

* Moves data-mapper pattern to Java 11

* Moves data-transfer-object pattern to Java 11

* Moves decorator pattern to Java 11

* Moves delegation pattern to Java 11

* Moves dependency-injection to Java 11

* Moves dirty-flag to Java 11

* Moves double-buffer to Java 11

* Moves double-checked-locking to Java 11

* Moves double-dispatch to Java 11

* Corrects with changes thats breaking test cases
This commit is contained in:
Anurag Agarwal
2019-12-15 00:02:45 +05:30
committed by Ilkka Seppälä
parent 5681684157
commit ea57934db6
75 changed files with 576 additions and 713 deletions

View File

@@ -23,9 +23,9 @@
package com.iluwatar.doublechecked.locking;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,15 +50,13 @@ public class App {
* @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(() -> {
while (inventory.addItem(new Item())) {
LOGGER.info("Adding another item");
}
});
}
final var inventory = new Inventory(1000);
var executorService = Executors.newFixedThreadPool(3);
IntStream.range(0, 3).<Runnable>mapToObj(i -> () -> {
while (inventory.addItem(new Item())) {
LOGGER.info("Adding another item");
}
}).forEach(executorService::execute);
executorService.shutdown();
try {

View File

@@ -24,7 +24,6 @@
package com.iluwatar.doublechecked.locking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -60,8 +59,8 @@ public class Inventory {
try {
if (items.size() < inventorySize) {
items.add(item);
LOGGER.info("{}: items.size()={}, inventorySize={}", Thread.currentThread(), items
.size(), inventorySize);
var thread = Thread.currentThread();
LOGGER.info("{}: items.size()={}, inventorySize={}", thread, items.size(), inventorySize);
return true;
}
} finally {
@@ -77,7 +76,7 @@ public class Inventory {
* @return All the items of the inventory, as an unmodifiable list
*/
public final List<Item> getItems() {
return Collections.unmodifiableList(items);
return List.copyOf(items);
}
}