Class StripedCounters<T>


  • public final class StripedCounters<T>
    extends java.lang.Object
    Duplicates a set of counters in a set of stripes, so that multiple threads can increment those counters without too much contention.

    Callers must first obtain a stripe for the current thread with stripeForCurrentThread(), then use increment(AtomicLongFieldUpdater, Object) or add(AtomicLongFieldUpdater, Object, long) to update one or more counters in that stripe. They must also provide a AtomicLongFieldUpdater to access a specific counter in the stripe - it should be defined as static final so that it can be inlined by the JIT.

    Since:
    9.0
    Author:
    Dan Berindei
    • Constructor Summary

      Constructors 
      Constructor Description
      StripedCounters​(java.util.function.Supplier<T> stripeSupplier)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater, T stripe, long delta)  
      long get​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater)  
      void increment​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater, T stripe)  
      void reset​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater)  
      T stripeForCurrentThread()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StripedCounters

        public StripedCounters​(java.util.function.Supplier<T> stripeSupplier)
    • Method Detail

      • increment

        public void increment​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater,
                              T stripe)
      • add

        public void add​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater,
                        T stripe,
                        long delta)
      • get

        public long get​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater)
      • reset

        public void reset​(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> updater)
      • stripeForCurrentThread

        public T stripeForCurrentThread()