From 0e3a4221fe622b572358ea8a656082f59f190f48 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 13 Mar 2020 16:33:34 +0100 Subject: [PATCH] BAEL-3855 --- .../lock/ConcurrentAccessBenchmark.java | 21 ++++++++++--------- .../baeldung/concurrent/lock/StripedLock.java | 4 ++-- 2 files changed, 13 insertions(+), 12 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 4dfbd8ea18..2dcaa5cb53 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 @@ -3,6 +3,7 @@ package com.baeldung.concurrent.lock; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import java.util.Map; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -25,28 +26,28 @@ public class ConcurrentAccessBenchmark { @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void singleLockHashMap() throws InterruptedException { - (new SingleLock()).doWork(new HashMap(), THREADS, SLOTS); + public Map singleLockHashMap() throws InterruptedException { + return (new SingleLock()).doWork(new HashMap(), THREADS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void stripedLockHashMap() throws InterruptedException { - (new StripedLock(BUCKETS)).doWork(new HashMap(), THREADS, SLOTS); + public Map stripedLockHashMap() throws InterruptedException { + return (new StripedLock(BUCKETS)).doWork(new HashMap(), THREADS, SLOTS); } - + @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void singleLockConcurrentHashMap() throws InterruptedException { - (new SingleLock()).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + public Map singleLockConcurrentHashMap() throws InterruptedException { + return (new SingleLock()).doWork(new ConcurrentHashMap(), THREADS, SLOTS); } - + @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void stripedLockConcurrentHashMap() throws InterruptedException { - (new StripedLock(BUCKETS)).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + public Map stripedLockConcurrentHashMap() throws InterruptedException { + return (new StripedLock(BUCKETS)).doWork(new ConcurrentHashMap(), THREADS, SLOTS); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index 8b661ecedc..46610c3b78 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -15,7 +15,7 @@ public class StripedLock extends ConcurrentAccessExperiment { protected Supplier putSupplier(Map map, int key) { return (()-> { - int bucket = key % stripedLock.size(); + int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); try { lock.tryLock(); @@ -33,7 +33,7 @@ public class StripedLock extends ConcurrentAccessExperiment { protected Supplier getSupplier(Map map, int key) { return (()-> { - int bucket = key % stripedLock.size(); + int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); try { lock.tryLock();