On Tue, Jan 24, 2023 at 1:26 PM <[email protected]> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> markt pushed a commit to branch 9.0.x
> in repository https://gitbox.apache.org/repos/asf/tomcat.git
>
> commit a7bf4d84f753d69acb66f5e45f5bc767a1d55e49
> Author: Mark Thomas <[email protected]>
> AuthorDate: Tue Jan 24 12:22:01 2023 +0000
>
> LongAdder is a better choice for statistics collection
Never heard of that before, but I see it's already there in Java 8.
Rémy
> ---
> java/org/apache/catalina/webresources/Cache.java | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/java/org/apache/catalina/webresources/Cache.java
> b/java/org/apache/catalina/webresources/Cache.java
> index 949117f521..4893a289cb 100644
> --- a/java/org/apache/catalina/webresources/Cache.java
> +++ b/java/org/apache/catalina/webresources/Cache.java
> @@ -22,6 +22,7 @@ import java.util.TreeSet;
> import java.util.concurrent.ConcurrentHashMap;
> import java.util.concurrent.ConcurrentMap;
> import java.util.concurrent.atomic.AtomicLong;
> +import java.util.concurrent.atomic.LongAdder;
>
> import org.apache.catalina.WebResource;
> import org.apache.catalina.WebResourceRoot.CacheStrategy;
> @@ -48,8 +49,8 @@ public class Cache {
> private int objectMaxSize = (int) maxSize / OBJECT_MAX_SIZE_FACTOR;
> private CacheStrategy cacheStrategy;
>
> - private AtomicLong lookupCount = new AtomicLong(0);
> - private AtomicLong hitCount = new AtomicLong(0);
> + private LongAdder lookupCount = new LongAdder();
> + private LongAdder hitCount = new LongAdder();
>
> private final ConcurrentMap<String, CachedResource> resourceCache = new
> ConcurrentHashMap<>();
>
> @@ -70,7 +71,7 @@ public class Cache {
> }
> }
>
> - lookupCount.incrementAndGet();
> + lookupCount.increment();
>
> CachedResource cacheEntry = resourceCache.get(path);
>
> @@ -138,14 +139,14 @@ public class Cache {
> cacheEntry.validateResource(useClassLoaderResources);
> }
> } else {
> - hitCount.incrementAndGet();
> + hitCount.increment();
> }
>
> return cacheEntry;
> }
>
> protected WebResource[] getResources(String path, boolean
> useClassLoaderResources) {
> - lookupCount.incrementAndGet();
> + lookupCount.increment();
>
> // Don't call noCache(path) since the class loader only caches
> // individual resources. Therefore, always cache collections here
> @@ -196,7 +197,7 @@ public class Cache {
> cacheEntry.validateResources(useClassLoaderResources);
> }
> } else {
> - hitCount.incrementAndGet();
> + hitCount.increment();
> }
>
> return cacheEntry.getWebResources();
> @@ -291,11 +292,11 @@ public class Cache {
> }
>
> public long getLookupCount() {
> - return lookupCount.get();
> + return lookupCount.sum();
> }
>
> public long getHitCount() {
> - return hitCount.get();
> + return hitCount.sum();
> }
>
> public void setObjectMaxSize(int objectMaxSize) {
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]