double value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic
variables. An AtomicDouble is used in applications such as atomic accumulation, and
cannot be used as a replacement for a Double. However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.
This class compares primitive double values in methods such as
compareAndSet by comparing their bitwise representation using Double#doubleToRawLongBits, which differs from both the primitive double == operator and
from Double#equals, as if implemented by:
static boolean bitEquals(double x, double y) {
long xBits = Double.doubleToRawLongBits(x);
long yBits = Double.doubleToRawLongBits(y);
return xBits == yBits;
}
It is possible to write a more scalable updater, at the cost of giving up strict atomicity. See for example DoubleAdder.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | |
| private static final AtomicLongFieldUpdater | |
| private transient volatile long |
| Access | Constructor and Description |
|---|---|
| public | AtomicDouble(double
the initial value initialValue)Creates a new |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final double | Returns: the updated valuethe update value x, DoubleBinaryOperator the accumulator function accumulatorFunction)Atomically updates the current value with the results of applying the given function to the current and given values. |
| public final double | Returns: the updated valuethe value to add delta)Atomically adds the given value to the current value. |
| public final boolean | Returns: true if successful. False return indicates that the actual value was not
bitwise equal to the expected value.the expected value expect, double the new value update)Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value. |
| public double | doubleValue()
Implements abstract java. AtomicDouble as a double.
|
| public float | floatValue()
Implements abstract java. AtomicDouble as a float after a narrowing primitive
conversion.
|
| public final double | |
| public final double | Returns: the previous valuethe update value x, DoubleBinaryOperator the accumulator function accumulatorFunction)Atomically updates the current value with the results of applying the given function to the current and given values. |
| public final double | Returns: the previous valuethe value to add delta)Atomically adds the given value to the current value. |
| public final double | Returns: the previous valuethe new value newValue)Atomically sets to the given value and returns the old value. |
| public final double | Returns: the previous valuethe update function updateFunction)Atomically updates the current value with the results of applying the given function. |
| public int | intValue()
Implements abstract java. AtomicDouble as an int after a narrowing primitive
conversion.
|
| public final void | |
| public long | longValue()
Implements abstract java. AtomicDouble as a long after a narrowing primitive
conversion.
|
| private void | |
| public final void | |
| public String | Returns: the String representation of the current valueOverrides java. |
| public final double | Returns: the updated valuethe update function updateFunction)Atomically updates the current value with the results of applying the given function. |
| public final boolean | Returns: true if successfulthe expected value expect, double the new value update)Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value. |
| private void |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| updater | back to summary |
|---|---|
| private static final AtomicLongFieldUpdater<AtomicDouble> updater | |
| value | back to summary |
|---|---|
| private transient volatile long value | |
| AtomicDouble | back to summary |
|---|---|
| public AtomicDouble(double initialValue) Creates a new
| |
| AtomicDouble | back to summary |
|---|---|
| public AtomicDouble() Creates a new | |
| accumulateAndGet | back to summary |
|---|---|
| public final double accumulateAndGet(double x, DoubleBinaryOperator accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values.
| |
| addAndGet | back to summary |
|---|---|
| public final double addAndGet(double delta) Atomically adds the given value to the current value.
| |
| compareAndSet | back to summary |
|---|---|
| public final boolean compareAndSet(double expect, double update) Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value.
| |
| doubleValue | back to summary |
|---|---|
| public double doubleValue() Implements abstract java. Returns the value of this
| |
| floatValue | back to summary |
|---|---|
| public float floatValue() Implements abstract java. Returns the value of this
| |
| get | back to summary |
|---|---|
| public final double get() Gets the current value.
| |
| getAndAccumulate | back to summary |
|---|---|
| public final double getAndAccumulate(double x, DoubleBinaryOperator accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values.
| |
| getAndAdd | back to summary |
|---|---|
| public final double getAndAdd(double delta) Atomically adds the given value to the current value.
| |
| getAndSet | back to summary |
|---|---|
| public final double getAndSet(double newValue) Atomically sets to the given value and returns the old value.
| |
| getAndUpdate | back to summary |
|---|---|
| public final double getAndUpdate(DoubleUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function.
| |
| intValue | back to summary |
|---|---|
| public int intValue() Implements abstract java. Returns the value of this
| |
| lazySet | back to summary |
|---|---|
| public final void lazySet(double newValue) Eventually sets to the given value.
| |
| longValue | back to summary |
|---|---|
| public long longValue() Implements abstract java. Returns the value of this
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException Reconstitutes the instance from a stream (that is, deserializes it). | |
| set | back to summary |
|---|---|
| public final void set(double newValue) Sets to the given value.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the String representation of the current value. | |
| updateAndGet | back to summary |
|---|---|
| public final double updateAndGet(DoubleUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function.
| |
| weakCompareAndSet | back to summary |
|---|---|
| public final boolean weakCompareAndSet(double expect, double update) Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value. May
fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate
alternative to
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Saves the state to a stream (that is, serializes it).
| |