double sum. When updates (method add) are
contended across threads, the set of variables may grow dynamically
to reduce contention. Method sum (or, equivalently doubleValue) returns the current total combined across the
variables maintaining the sum. The order of accumulation within or
across threads is not guaranteed. Thus, this class may not be
applicable if numerical stability is required, especially when
combining values of substantially different orders of magnitude.
This class is usually preferable to alternatives when multiple threads update a common value that is used for purposes such as summary statistics that are frequently updated but less frequently read.
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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | DoubleAdder.
Serialization proxy, used to avoid reference to the non-public Striped64 superclass in serialized forms. |
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public double | |
| public float | floatValue()
Implements abstract java. Returns the |
| public int | intValue()
Implements abstract java. Returns the |
| public long | longValue()
Implements abstract java. Returns the |
| private void | |
| public void | |
| public double | |
| public double | |
| public String | Returns: the String representation of thesumOverrides java. Returns the String representation of the |
| private Object | Returns: aSerializationProxy
representing the state of this instanceReturns a SerializationProxy representing the state of this instance. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| DoubleAdder | back to summary |
|---|---|
| public DoubleAdder() Creates a new adder with initial sum of zero. | |
| add | back to summary |
|---|---|
| public void add(double x) Adds the given value.
| |
| doubleValue | back to summary |
|---|---|
| public double doubleValue() Implements abstract java. Equivalent to
| |
| floatValue | back to summary |
|---|---|
| public float floatValue() Implements abstract java. Returns the | |
| intValue | back to summary |
|---|---|
| public int intValue() Implements abstract java. Returns the | |
| longValue | back to summary |
|---|---|
| public long longValue() Implements abstract java. Returns the | |
| readObject | back to summary |
|---|---|
private void readObject(ObjectInputStream s) throws InvalidObjectException
| |
| reset | back to summary |
|---|---|
| public void reset() 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. | |
| sum | back to summary |
|---|---|
| public double 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. Also, because floating-point arithmetic is not strictly associative, the returned result need not be identical to the value that would be obtained in a sequential series of updates to a single variable.
| |
| sumThenReset | back to summary |
|---|---|
| public double sumThenReset() Equivalent in effect to
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the String representation of the | |
| writeReplace | back to summary |
|---|---|
| private Object writeReplace() Returns a SerializationProxy representing the state of this instance.
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final long | |
| private final double | value
The current value returned by sum(). |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private Object | Returns: aDoubleAdder object with initial state
held by this proxyReturns a |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| value | back to summary |
|---|---|
| private final double value The current value returned by sum(). | |
| SerializationProxy | back to summary |
|---|---|
| pack-priv SerializationProxy(DoubleAdder a) | |
| readResolve | back to summary |
|---|---|
| private Object readResolve() Returns a
| |