Skip to content

Commit 76e8a5c

Browse files
committed
remove unnecessary sync
1 parent 7d3fd31 commit 76e8a5c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

client/src/main/java/io/split/client/impressions/ImpressionObserver.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.cache.Cache;
44
import com.google.common.cache.CacheBuilder;
55
import io.split.client.dtos.KeyImpression;
6+
import org.apache.http.annotation.NotThreadSafe;
67

78
/*
89
According to guava's docs (https://guava.dev/releases/18.0/api/docs/com/google/common/annotations/Beta.html),
@@ -12,27 +13,26 @@
1213
*/
1314

1415
@SuppressWarnings("UnstableApiUsage")
16+
@NotThreadSafe
1517
public class ImpressionObserver {
1618

1719
private final Cache<Long, Long> _cache;
1820

1921
public ImpressionObserver(long size) {
2022
_cache = CacheBuilder.newBuilder()
2123
.maximumSize(size)
24+
.concurrencyLevel(4) // Just setting the default value explicitly
2225
.build();
2326
}
24-
27+
2528
public Long testAndSet(KeyImpression impression) {
2629
if (null == impression) {
2730
return null;
2831
}
2932

3033
Long hash = ImpressionHasher.process(impression);
31-
32-
synchronized(this) {
33-
Long previous = _cache.getIfPresent(hash);
34-
_cache.put(hash, impression.time);
35-
return previous;
36-
}
34+
Long previous = _cache.getIfPresent(hash);
35+
_cache.put(hash, impression.time);
36+
return previous;
3737
}
3838
}

client/src/test/java/io/split/client/impressions/ImpressionHasherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void doesNotCrash() {
6767

6868
imp1.treatment = null;
6969
assertNotNull(ImpressionHasher.process(imp1));
70-
70+
7171
assertNull(ImpressionHasher.process(null));
7272
}
7373
}

0 commit comments

Comments
 (0)