ctubbsii commented on a change in pull request #1965:
URL: https://github.com/apache/accumulo/pull/1965#discussion_r594834775



##########
File path: 
core/src/main/java/org/apache/accumulo/core/util/ratelimit/SharedRateLimiterFactory.java
##########
@@ -87,12 +90,12 @@ public static synchronized SharedRateLimiterFactory 
getInstance(AccumuloConfigur
   public RateLimiter create(String name, RateProvider rateProvider) {
     synchronized (activeLimiters) {
       if (activeLimiters.containsKey(name)) {
-        return activeLimiters.get(name);
+        return activeLimiters.get(name).get();
       } else {
         long initialRate;
         initialRate = rateProvider.getDesiredRate();
         SharedRateLimiter limiter = new SharedRateLimiter(name, rateProvider, 
initialRate);
-        activeLimiters.put(name, limiter);
+        activeLimiters.put(name, new WeakReference<>(limiter));
         return limiter;

Review comment:
       What I was referring to was the ability to use something like:
   
   ```java
     var storedValue = map.compute(key, (key, oldValue) -> {
       if (oldValue != null) {
         return oldValue; // no change
       }
       return generateNewValueForKey(key);
     });
   ```
   
   It won't work in this case, because we'd be storing a WeakReference in the 
value, and we'd need to keep a strong reference around before returning from 
the lambda inside the compute method. We could do that by setting a final 
AtomicReference from within the compute method... but it's more complicated 
than just using get and put instead of compute, so it's not worth it. See my PR 
against your PR for a better suggestion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to