You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/05/26 10:47:04 UTC
[3/3] camel git commit: CAMEL-11339: Optimise to use LongAdder
instead of AtomicLong
CAMEL-11339: Optimise to use LongAdder instead of AtomicLong
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0959a75b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0959a75b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0959a75b
Branch: refs/heads/master
Commit: 0959a75b73b8dd4a2f01fdc0f4a40c51853a824d
Parents: 9d2f1df
Author: Claus Ibsen <da...@apache.org>
Authored: Fri May 26 11:51:45 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri May 26 12:09:36 2017 +0200
----------------------------------------------------------------------
.../camel/impl/DefaultEndpointRegistry.java | 2 +-
.../camel/impl/DefaultTransformerRegistry.java | 2 +-
.../camel/impl/DefaultValidatorRegistry.java | 2 +-
.../java/org/apache/camel/util/LRUCache.java | 26 ++++++++++----------
4 files changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0959a75b/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointRegistry.java
index 70199a4..71175a4 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointRegistry.java
@@ -64,7 +64,7 @@ public class DefaultEndpointRegistry extends LRUCache<EndpointKey, Endpoint> imp
if (answer == null) {
answer = super.get(o);
} else {
- hits.incrementAndGet();
+ hits.increment();
}
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0959a75b/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
index 52a9391..feeb5f0 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
@@ -118,7 +118,7 @@ public class DefaultTransformerRegistry extends LRUCache<TransformerKey, Transfo
if (answer == null) {
answer = super.get(o);
} else {
- hits.incrementAndGet();
+ hits.increment();
}
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0959a75b/camel-core/src/main/java/org/apache/camel/impl/DefaultValidatorRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultValidatorRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultValidatorRegistry.java
index 85f6690..bcd91d7 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultValidatorRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultValidatorRegistry.java
@@ -82,7 +82,7 @@ public class DefaultValidatorRegistry extends LRUCache<ValidatorKey, Validator>
if (answer == null) {
answer = super.get(o);
} else {
- hits.incrementAndGet();
+ hits.increment();
}
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0959a75b/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/LRUCache.java b/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
index dda974f..87c1fb0 100644
--- a/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
+++ b/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
@@ -20,7 +20,7 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
@@ -43,9 +43,9 @@ import org.slf4j.LoggerFactory;
public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K, V>, Serializable {
private static final Logger LOG = LoggerFactory.getLogger(LRUCache.class);
- protected final AtomicLong hits = new AtomicLong();
- protected final AtomicLong misses = new AtomicLong();
- protected final AtomicLong evicted = new AtomicLong();
+ protected final LongAdder hits = new LongAdder();
+ protected final LongAdder misses = new LongAdder();
+ protected final LongAdder evicted = new LongAdder();
private int maxCacheSize = 10000;
private boolean stopOnEviction;
@@ -127,9 +127,9 @@ public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K, V>, Seriali
public V get(Object o) {
V answer = map.get(o);
if (answer != null) {
- hits.incrementAndGet();
+ hits.increment();
} else {
- misses.incrementAndGet();
+ misses.increment();
}
return answer;
}
@@ -192,7 +192,7 @@ public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K, V>, Seriali
@Override
public void onRemoval(K key, V value, RemovalCause cause) {
if (cause.wasEvicted()) {
- evicted.incrementAndGet();
+ evicted.increment();
LOG.trace("onRemoval {} -> {}", key, value);
if (stopOnEviction) {
try {
@@ -209,21 +209,21 @@ public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K, V>, Seriali
* Gets the number of cache hits
*/
public long getHits() {
- return hits.get();
+ return hits.longValue();
}
/**
* Gets the number of cache misses.
*/
public long getMisses() {
- return misses.get();
+ return misses.longValue();
}
/**
* Gets the number of evicted entries.
*/
public long getEvicted() {
- return evicted.get();
+ return evicted.longValue();
}
/**
@@ -237,9 +237,9 @@ public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K, V>, Seriali
* Rest the cache statistics such as hits and misses.
*/
public void resetStatistics() {
- hits.set(0);
- misses.set(0);
- evicted.set(0);
+ hits.reset();
+ misses.reset();
+ evicted.reset();
}
public void cleanUp() {