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. 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.
This class extends Number, but does not define
methods such as hashCode and compareTo because
instances are expected to be mutated, and so are not useful as
collection keys.
JSR 166e Note
This class is targeted to be placed in java.util.concurrent.atomic.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public double | doubleValue()
Implements abstract java. sum as a double after a widening
primitive conversion.
|
| public float | floatValue()
Implements abstract java. sum as a float
after a widening primitive conversion.
|
| pack-priv final long | fn(long
the current value (of either base or a cell) v, long the argument from a user update call x)Implements abstract net. |
| public void | |
| public int | intValue()
Implements abstract java. sum as an int after a narrowing
primitive conversion.
|
| public long | |
| private void | |
| public void | |
| public long | |
| public long | |
| public String | Returns: the String representation of thesumOverrides java. sum.
|
| private void |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| LongAdder | back to summary |
|---|---|
| public LongAdder() Creates a new adder with initial sum of zero. | |
| add | back to summary |
|---|---|
| public void add(long x) Adds the given value.
| |
| decrement | back to summary |
|---|---|
| public void decrement() Equivalent to | |
| doubleValue | back to summary |
|---|---|
| public double doubleValue() Implements abstract java. Returns the
| |
| floatValue | back to summary |
|---|---|
| public float floatValue() Implements abstract java. Returns the
| |
| fn | back to summary |
|---|---|
| pack-priv final long fn(long v, long x) Implements abstract net. Version of plus for use in retryUpdate
| |
| increment | back to summary |
|---|---|
| public void increment() Equivalent to | |
| intValue | back to summary |
|---|---|
| public int intValue() Implements abstract java. Returns the
| |
| longValue | back to summary |
|---|---|
| public long longValue() Implements abstract java. Equivalent to
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException | |
| 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 long 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.
| |
| sumThenReset | back to summary |
|---|---|
| public long sumThenReset() Equivalent in effect to
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the String representation of the | |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException | |