V - The type of object referred to by this reference
public class AtomicReference<V> extends Objectimplements Serializable
java.util.concurrent.atomic package specification for description of the properties of atomic variables.
| Constructor and Description |
|---|
AtomicReference()
Creates a new AtomicReference with null initial value.
|
AtomicReference(V initialValue)
Creates a new AtomicReference with the given initial value.
|
| Modifier and Type | Method and Description |
|---|---|
V |
accumulateAndGet(V x, BinaryOperator
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.
|
boolean |
compareAndSet(V expect, V update)
Atomically sets the value to the given updated value if the current value
== the expected value.
|
V |
get()
Gets the current value.
|
V |
getAndAccumulate(V x, BinaryOperator
Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.
|
V |
getAndSet(V newValue)
Atomically sets to the given value and returns the old value.
|
V |
getAndUpdate(UnaryOperator
Atomically updates the current value with the results of applying the given function, returning the previous value.
|
void |
lazySet(V newValue)
Eventually sets to the given value.
|
void |
set(V newValue)
Sets to the given value.
|
String |
toString()
Returns the String representation of the current value.
|
V |
updateAndGet(UnaryOperator
Atomically updates the current value with the results of applying the given function, returning the updated value.
|
boolean |
weakCompareAndSet(V expect, V update)
Atomically sets the value to the given updated value if the current value
== the expected value.
|
public AtomicReference(V initialValue)
initialValue - the initial value
public AtomicReference()
public final V get()
public final void set(V newValue)
newValue - the new value
public final void lazySet(V newValue)
newValue - the new value
public final boolean compareAndSet(V expect, V update)
== the expected value.
expect - the expected value
update - the new value
true if successful. False return indicates that the actual value was not equal to the expected value.
public final boolean weakCompareAndSet(V expect, V update)
== the expected value.
May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.
expect - the expected value
update - the new value
true if successful
public final V getAndSet(V newValue)
newValue - the new value
public final V getAndUpdate(UnaryOperator<V> updateFunction)
updateFunction - a side-effect-free function
public final V updateAndGet(UnaryOperator<V> updateFunction)
updateFunction - a side-effect-free function
public final V getAndAccumulate(V x, BinaryOperator<V> accumulatorFunction)
x - the update value
accumulatorFunction - a side-effect-free function of two arguments
public final V accumulateAndGet(V x, BinaryOperator<V> accumulatorFunction)
x - the update value
accumulatorFunction - a side-effect-free function of two arguments