Class ReflectionLongAdderCounter

  • All Implemented Interfaces:
    LongCounter

    public final class ReflectionLongAdderCounter
    extends java.lang.Object
    implements LongCounter
    A LongCounter that is implemented with a JDK8 LongAdder. Instantiates the object and invokes methods reflectively to avoid a compile time dependency on LongAdder.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.reflect.Method addMethod  
      private static java.lang.reflect.Constructor<?> defaultConstructor  
      private static java.lang.RuntimeException initializationException  
      private java.lang.Object instance  
      private static java.util.logging.Logger logger  
      private static java.lang.Object[] one  
      private static java.lang.reflect.Method sumMethod  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long delta)
      Adds the delta to this counter.
      (package private) static boolean isAvailable()
      Returns true if the environment supports LongAdder.
      long value()
      Returns the value of this counter.
      • Methods inherited from class java.lang.Object

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

      • logger

        private static final java.util.logging.Logger logger
      • defaultConstructor

        private static final java.lang.reflect.Constructor<?> defaultConstructor
      • addMethod

        private static final java.lang.reflect.Method addMethod
      • sumMethod

        private static final java.lang.reflect.Method sumMethod
      • initializationException

        private static final java.lang.RuntimeException initializationException
      • instance

        private final java.lang.Object instance
      • one

        private static final java.lang.Object[] one
    • Constructor Detail

      • ReflectionLongAdderCounter

        ReflectionLongAdderCounter()
    • Method Detail

      • isAvailable

        static boolean isAvailable()
        Returns true if the environment supports LongAdder. In other words, we are running in >= JDK8.
      • add

        public void add​(long delta)
        Description copied from interface: LongCounter
        Adds the delta to this counter.
        Specified by:
        add in interface LongCounter
      • value

        public long value()
        Description copied from interface: LongCounter
        Returns the value of this counter.
        Specified by:
        value in interface LongCounter