Packages

c

kamon.jsr166

LongAdder

class LongAdder extends Striped64 with Serializable

One or more variables that together maintain an initially zero long sum. When updates (method #add) are contended across threads, the set of variables may grow dynamically to reduce contention. Method #sum (or, equivalently, #longValue) returns the current total combined across the variables maintaining the sum.

This class is usually preferable to java.util.concurrent.atomic.AtomicLong when multiple threads update a common sum that is used for purposes such as collecting statistics, not for fine-grained synchronization control. Under low update contention, the two classes have similar characteristics. But under high contention, expected throughput of this class is significantly higher, at the expense of higher space consumption.

LongAdders can be used with a java.util.concurrent.ConcurrentHashMap to maintain a scalable frequency map (a form of histogram or multiset). For example, to add a count to a ConcurrentHashMap freqs, initializing if not already present, you can use freqs.computeIfAbsent(key, k -> new LongAdder()).increment();

This class extends Number, but does not define methods such as equals, hashCode and compareTo because instances are expected to be mutated, and so are not useful as collection keys.

Since

1.8

Linear Supertypes
Striped64, Number, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LongAdder
  2. Striped64
  3. Number
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new LongAdder()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def add(x: Long): Unit

    Adds the given value.

    Adds the given value.

    x

    the value to add

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def byteValue(): Byte
    Definition Classes
    Number
  7. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def decrement(): Unit

    Equivalent to add(-1).

    Equivalent to add(-1).

  9. def doubleValue(): Double

    Returns the #sum as a double after a widening primitive conversion.

    Returns the #sum as a double after a widening primitive conversion.

    Definition Classes
    LongAdder → Number
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. def floatValue(): Float

    Returns the #sum as a float after a widening primitive conversion.

    Returns the #sum as a float after a widening primitive conversion.

    Definition Classes
    LongAdder → Number
  14. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  16. def increment(): Unit

    Equivalent to add(1).

    Equivalent to add(1).

  17. def intValue(): Int

    Returns the #sum as an int after a narrowing primitive conversion.

    Returns the #sum as an int after a narrowing primitive conversion.

    Definition Classes
    LongAdder → Number
  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. def longValue(): Long

    Equivalent to #sum.

    Equivalent to #sum.

    returns

    the sum

    Definition Classes
    LongAdder → Number
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  23. def reset(): Unit

    Resets variables maintaining the sum to zero.

    Resets variables maintaining the sum to zero. This method may be a useful alternative to creating a new adder, but is only effective if there are no concurrent updates. Because this method is intrinsically racy, it should only be used when it is known that no threads are concurrently updating.

  24. def shortValue(): Short
    Definition Classes
    Number
  25. def sum(): Long

    Returns the current sum.

    Returns the current sum. The returned value is NOT an atomic snapshot; invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated.

    returns

    the sum

  26. def sumAndReset(): Long

    Atomic variant of #sumThenReset

    Atomic variant of #sumThenReset

    returns

    the sum

  27. def sumThenReset(): Long

    Equivalent in effect to #sum followed by #reset.

    Equivalent in effect to #sum followed by #reset. This method may apply for example during quiescent points between multithreaded computations. If there are updates concurrent with this method, the returned value is not guaranteed to be the final value occurring before the reset.

    returns

    the sum

  28. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  29. def toString(): String

    Returns the String representation of the #sum.

    Returns the String representation of the #sum.

    returns

    the String representation of the #sum

    Definition Classes
    LongAdder → AnyRef → Any
  30. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Striped64

Inherited from Number

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped