Skip to content

DoubleAdder and DoubleAccumulator

DoubleAdder and DoubleAccumulator are concurrent components introduced in Java 8 (as part of Striped64) designed to maintain thread safety in lock-free environments.^[600-developer-java-java-base-java-runtime-number.md] They are typically used for high-throughput counting or accumulation operations under concurrent access.

Relationship and Equivalence

The DoubleAdder class is functionally equivalent to a specific configuration of DoubleAccumulator.^[600-developer-java-java-base-java-runtime-number.md] Specifically, creating a new DoubleAdder instance is the same as initializing a DoubleAccumulator with a summation function and an initial identity value of zero^[600-developer-java-java-base-java-runtime-number.md]:

The call new DoubleAdder() is equivalent to new DoubleAccumulator((x, y) -> x + y, 0.0)

This relationship mirrors the behavior found in the Long variants of these classes (e.g., LongAdder vs. LongAccumulator).^[600-developer-java-java-base-java-runtime-number.md]

  • Java
  • [[Concurrency]]
  • Striped64
  • [[LongAdder and LongAccumulator]]

Sources

  • 600-developer-java-java-base-java-runtime-number.md