Class AtomicDouble
java.lang.Object
java.lang.Number
com.google.common.util.concurrent.AtomicDouble
- All Implemented Interfaces:
Serializable
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
A
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(double, double)
by comparing their
bitwise representation using Double.doubleToRawLongBits(double)
,
which differs from both the primitive double ==
operator
and from Double.equals(java.lang.Object)
, 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 and DoubleMaxUpdater.
- Since:
- 11.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Creates a newAtomicDouble
with initial value0.0
.AtomicDouble
(double initialValue) Deprecated.Creates a newAtomicDouble
with the given initial value. -
Method Summary
Modifier and TypeMethodDescriptionfinal double
addAndGet
(double delta) Deprecated.Atomically adds the given value to the current value.final boolean
compareAndSet
(double expect, double update) Deprecated.Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value.double
Deprecated.Returns the value of thisAtomicDouble
as adouble
.float
Deprecated.Returns the value of thisAtomicDouble
as afloat
after a narrowing primitive conversion.final double
get()
Deprecated.Gets the current value.final double
getAndAdd
(double delta) Deprecated.Atomically adds the given value to the current value.final double
getAndSet
(double newValue) Deprecated.Atomically sets to the given value and returns the old value.int
intValue()
Deprecated.Returns the value of thisAtomicDouble
as anint
after a narrowing primitive conversion.final void
lazySet
(double newValue) Deprecated.Eventually sets to the given value.long
Deprecated.Returns the value of thisAtomicDouble
as along
after a narrowing primitive conversion.final void
set
(double newValue) Deprecated.Sets to the given value.toString()
Deprecated.Returns the String representation of the current value.final boolean
weakCompareAndSet
(double expect, double update) Deprecated.Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
AtomicDouble
public AtomicDouble(double initialValue) Deprecated.Creates a newAtomicDouble
with the given initial value.- Parameters:
initialValue
- the initial value
-
AtomicDouble
public AtomicDouble()Deprecated.Creates a newAtomicDouble
with initial value0.0
.
-
-
Method Details
-
get
public final double get()Deprecated.Gets the current value.- Returns:
- the current value
-
set
public final void set(double newValue) Deprecated.Sets to the given value.- Parameters:
newValue
- the new value
-
lazySet
public final void lazySet(double newValue) Deprecated.Eventually sets to the given value.- Parameters:
newValue
- the new value
-
getAndSet
public final double getAndSet(double newValue) Deprecated.Atomically sets to the given value and returns the old value.- Parameters:
newValue
- the new value- Returns:
- the previous value
-
compareAndSet
public final boolean compareAndSet(double expect, double update) Deprecated.Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value.- Parameters:
expect
- the expected valueupdate
- the new value- Returns:
true
if successful. False return indicates that the actual value was not bitwise equal to the expected value.
-
weakCompareAndSet
public final boolean weakCompareAndSet(double expect, double update) Deprecated.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
compareAndSet
.- Parameters:
expect
- the expected valueupdate
- the new value- Returns:
true
if successful
-
getAndAdd
public final double getAndAdd(double delta) Deprecated.Atomically adds the given value to the current value.- Parameters:
delta
- the value to add- Returns:
- the previous value
-
addAndGet
public final double addAndGet(double delta) Deprecated.Atomically adds the given value to the current value.- Parameters:
delta
- the value to add- Returns:
- the updated value
-
toString
Deprecated.Returns the String representation of the current value. -
intValue
public int intValue()Deprecated.Returns the value of thisAtomicDouble
as anint
after a narrowing primitive conversion. -
longValue
public long longValue()Deprecated.Returns the value of thisAtomicDouble
as along
after a narrowing primitive conversion. -
floatValue
public float floatValue()Deprecated.Returns the value of thisAtomicDouble
as afloat
after a narrowing primitive conversion.- Specified by:
floatValue
in classNumber
-
doubleValue
public double doubleValue()Deprecated.Returns the value of thisAtomicDouble
as adouble
.- Specified by:
doubleValue
in classNumber
-