Striped64¶
Striped64 is a concurrent component introduced in Java 8 to support accumulators.^[600-developer__java__java-base__java-Runtime-Number.md] It is designed to operate within concurrent environments for performing counting operations.^[600-developer__java__java-base__java-Runtime-Number.md]
The implementation is characterized as lock-free while remaining thread-safe.^[600-developer__java__java-base__java-Runtime-Number.md]
Implementations¶
Striped64 serves as the foundation for several high-performance accumulator classes in the java.lang package, specifically supporting operations for long and double primitive types^[600-developer__java__java-base__java-Runtime-Number.md]:
- LongAdder
- LongAccumulator
- [[DoubleAdder]]
- [[DoubleAccumulator]]
Relationship to Adders and Accumulators¶
The Adder classes are essentially specialized configurations of the Accumulator classes.
For example, creating a new LongAdder is functionally equivalent to creating a LongAccumulator with a sum function and an initial identity value of zero^[600-developer__java__java-base__java-Runtime-Number.md]:
// Equivalent definitions
new [LongAdder](<./longadder.md>)()
new [LongAccumulator](<./longaccumulator.md>)((x, y) -> x + y, 0L)
Similarly, DoubleAdder is equivalent to a DoubleAccumulator initialized to sum values starting from 0.0^[600-developer__java__java-base__java-Runtime-Number.md]:
// Equivalent definitions
new DoubleAdder()
new [LongAccumulator](<./longaccumulator.md>)((x, y) -> x + y, 0.0)
Related Concepts¶
- [[Java Concurrency]]
- [[Atomic Variables]]
- [[java.lang.Number]]
Sources¶
^[600-developer__java__java-base__java-Runtime-Number.md]