From 21c42ebebc0ef10f2e0889be380fb00f87a6b5c1 Mon Sep 17 00:00:00 2001 From: jsgrah-spring Date: Wed, 30 Nov 2022 18:49:52 +0100 Subject: [PATCH] JAVA-12387. Correct/Rename THREADS to TASKS and int threads to int tasks. (#13084) --- .../concurrent/lock/ConcurrentAccessBenchmark.java | 10 +++++----- .../concurrent/lock/ConcurrentAccessExperiment.java | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java index ceb53ce077..28231a15a8 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java @@ -19,7 +19,7 @@ import org.openjdk.jmh.annotations.Warmup; @Warmup(iterations = 0) public class ConcurrentAccessBenchmark { static final int SLOTS = 4; - static final int THREADS = 10000; + static final int TASKS = 10000; static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; SingleLock singleLock = new SingleLock(); StripedLock stripedLock = new StripedLock(BUCKETS); @@ -28,27 +28,27 @@ public class ConcurrentAccessBenchmark { @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map singleLockHashMap() throws InterruptedException { - return singleLock.doWork(new HashMap(), THREADS, SLOTS); + return singleLock.doWork(new HashMap(), TASKS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map stripedLockHashMap() throws InterruptedException { - return stripedLock.doWork(new HashMap(), THREADS, SLOTS); + return stripedLock.doWork(new HashMap(), TASKS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map singleLockConcurrentHashMap() throws InterruptedException { - return singleLock.doWork(new ConcurrentHashMap(), THREADS, SLOTS); + return singleLock.doWork(new ConcurrentHashMap(), TASKS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map stripedLockConcurrentHashMap() throws InterruptedException { - return stripedLock.doWork(new ConcurrentHashMap(), THREADS, SLOTS); + return stripedLock.doWork(new ConcurrentHashMap(), TASKS, SLOTS); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java index ec6d3895da..b24f0c8b19 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java @@ -7,10 +7,10 @@ import com.google.common.base.Supplier; public abstract class ConcurrentAccessExperiment { - public final Map doWork(Map map, int threads, int slots) { - CompletableFuture[] requests = new CompletableFuture[threads * slots]; + public final Map doWork(Map map, int tasks, int slots) { + CompletableFuture[] requests = new CompletableFuture[tasks * slots]; - for (int i = 0; i < threads; i++) { + for (int i = 0; i < tasks; i++) { requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i)); requests[slots * i + 1] = CompletableFuture.supplyAsync(getSupplier(map, i)); requests[slots * i + 2] = CompletableFuture.supplyAsync(getSupplier(map, i));