BAEL-3855
identation, moved to new module, removed needless classes, better benchmark
This commit is contained in:
parent
d144322c45
commit
d01b7be0b6
@ -1,7 +1,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.concurrent.lock</groupId>
|
||||
<artifactId>lock-striping</artifactId>
|
||||
<artifactId>core-java-concurrency-collections-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
|
@ -6,6 +6,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
@ -16,24 +17,18 @@ import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
|
||||
@State(Scope.Thread)
|
||||
@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.MILLISECONDS)
|
||||
@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 3)
|
||||
public class BenchMark {
|
||||
ConcurrentAccessMap accessMyMap;
|
||||
|
||||
@Param({"HashMap", "HashMap with Lock", "HashMap with Striped Lock",
|
||||
"ConcurrentHashMap", "ConcurrentHashMap with Lock", "ConcurrentHashMap with Striped Lock"})
|
||||
@Param({"HashMap with Lock", "HashMap with Striped Lock",
|
||||
"ConcurrentHashMap with Lock", "ConcurrentHashMap with Striped Lock"})
|
||||
private String type;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
switch (type) {
|
||||
case "HashMap":
|
||||
accessMyMap = new NoLock(getHashMap());
|
||||
break;
|
||||
case "ConcurrentHashMap":
|
||||
accessMyMap = new NoLock(getConcurrentHashMap());
|
||||
break;
|
||||
case "HashMap with Lock":
|
||||
accessMyMap = new CoarseGrained(getHashMap());
|
||||
break;
|
||||
|
@ -10,7 +10,7 @@ public abstract class ConcurrentAccessMap {
|
||||
static final int THREADS = 10000;
|
||||
static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS;
|
||||
private CompletableFuture<?>[] requests;
|
||||
Map<String, String> map;
|
||||
protected Map<String, String> map;
|
||||
|
||||
public ConcurrentAccessMap(Map<String, String> map) {
|
||||
this.map = map;
|
||||
|
@ -1,34 +0,0 @@
|
||||
package com.baeldung.concurrent.lock;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
public class NoLock extends ConcurrentAccessMap {
|
||||
|
||||
public NoLock(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
protected Supplier<?> putSupplier(int x) {
|
||||
return (()-> {
|
||||
boolean done = false;
|
||||
while(!done) {
|
||||
map.put("key" + x, "value" + x);
|
||||
done = true;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
protected Supplier<?> getSupplier(int x) {
|
||||
return (()-> {
|
||||
boolean done = false;
|
||||
while(!done) {
|
||||
map.get("key" + x);
|
||||
done = true;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user