V
- The type of object referred to by this referenceSerializable
public class AtomicReference<V> extends Object implements Serializable
VarHandle
specification for descriptions of the properties of
atomic accesses.Constructor | 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 | Description |
---|---|---|
V |
accumulateAndGet(V x,
BinaryOperator<V> accumulatorFunction) |
Atomically updates the current value with the results of
applying the given function to the current and given values,
returning the updated value.
|
V |
compareAndExchange(V expectedValue,
V newValue) |
Atomically sets the value to
newValue if the current value,
referred to as the witness value, == expectedValue ,
with memory effects as specified by
VarHandle.compareAndExchange(java.lang.Object...) . |
V |
compareAndExchangeAcquire(V expectedValue,
V newValue) |
Atomically sets the value to
newValue if the current value,
referred to as the witness value, == expectedValue ,
with memory effects as specified by
VarHandle.compareAndExchangeAcquire(java.lang.Object...) . |
V |
compareAndExchangeRelease(V expectedValue,
V newValue) |
Atomically sets the value to
newValue if the current value,
referred to as the witness value, == expectedValue ,
with memory effects as specified by
VarHandle.compareAndExchangeRelease(java.lang.Object...) . |
boolean |
compareAndSet(V expectedValue,
V newValue) |
Atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by VarHandle.compareAndSet(java.lang.Object...) . |
V |
get() |
Returns the current value,
with memory effects as specified by
VarHandle.getVolatile(java.lang.Object...) . |
V |
getAcquire() |
Returns the current value,
with memory effects as specified by
VarHandle.getAcquire(java.lang.Object...) . |
V |
getAndAccumulate(V x,
BinaryOperator<V> accumulatorFunction) |
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 the value to
newValue and returns the old value,
with memory effects as specified by VarHandle.getAndSet(java.lang.Object...) . |
V |
getAndUpdate(UnaryOperator<V> updateFunction) |
Atomically updates the current value with the results of
applying the given function, returning the previous value.
|
V |
getOpaque() |
Returns the current value,
with memory effects as specified by
VarHandle.getOpaque(java.lang.Object...) . |
V |
getPlain() |
Returns the current value, with memory semantics of reading as
if the variable was declared non-
volatile . |
void |
lazySet(V newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...) . |
void |
set(V newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setVolatile(java.lang.Object...) . |
void |
setOpaque(V newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setOpaque(java.lang.Object...) . |
void |
setPlain(V newValue) |
Sets the value to
newValue , with memory semantics
of setting as if the variable was declared non-volatile
and non-final . |
void |
setRelease(V newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...) . |
String |
toString() |
Returns the String representation of the current value.
|
V |
updateAndGet(UnaryOperator<V> updateFunction) |
Atomically updates the current value with the results of
applying the given function, returning the updated value.
|
boolean |
weakCompareAndSet(V expectedValue,
V newValue) |
Deprecated.
This method has plain memory effects but the method
name implies volatile memory effects (see methods such as
compareAndExchange(V, V) and compareAndSet(V, V) ). To avoid
confusion over plain or volatile memory effects it is recommended that
the method weakCompareAndSetPlain(V, V) be used instead. |
boolean |
weakCompareAndSetAcquire(V expectedValue,
V newValue) |
Possibly atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by
VarHandle.weakCompareAndSetAcquire(java.lang.Object...) . |
boolean |
weakCompareAndSetPlain(V expectedValue,
V newValue) |
Possibly atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by VarHandle.weakCompareAndSetPlain(java.lang.Object...) . |
boolean |
weakCompareAndSetRelease(V expectedValue,
V newValue) |
Possibly atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by
VarHandle.weakCompareAndSetRelease(java.lang.Object...) . |
boolean |
weakCompareAndSetVolatile(V expectedValue,
V newValue) |
Possibly atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by
VarHandle.weakCompareAndSet(java.lang.Object...) . |
public AtomicReference(V initialValue)
initialValue
- the initial valuepublic AtomicReference()
public final V get()
VarHandle.getVolatile(java.lang.Object...)
.public final void set(V newValue)
newValue
,
with memory effects as specified by VarHandle.setVolatile(java.lang.Object...)
.newValue
- the new valuepublic final void lazySet(V newValue)
newValue
,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...)
.newValue
- the new valuepublic final boolean compareAndSet(V expectedValue, V newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by VarHandle.compareAndSet(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successful. False return indicates that
the actual value was not equal to the expected value.@Deprecated(since="9") public final boolean weakCompareAndSet(V expectedValue, V newValue)
compareAndExchange(V, V)
and compareAndSet(V, V)
). To avoid
confusion over plain or volatile memory effects it is recommended that
the method weakCompareAndSetPlain(V, V)
be used instead.newValue
if the current value == expectedValue
,
with memory effects as specified by VarHandle.weakCompareAndSetPlain(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulweakCompareAndSetPlain(V, V)
public final boolean weakCompareAndSetPlain(V expectedValue, V newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by VarHandle.weakCompareAndSetPlain(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulpublic final V getAndSet(V newValue)
newValue
and returns the old value,
with memory effects as specified by VarHandle.getAndSet(java.lang.Object...)
.newValue
- the new valuepublic final V getAndUpdate(UnaryOperator<V> updateFunction)
updateFunction
- a side-effect-free functionpublic final V updateAndGet(UnaryOperator<V> updateFunction)
updateFunction
- a side-effect-free functionpublic final V getAndAccumulate(V x, BinaryOperator<V> accumulatorFunction)
x
- the update valueaccumulatorFunction
- a side-effect-free function of two argumentspublic final V accumulateAndGet(V x, BinaryOperator<V> accumulatorFunction)
x
- the update valueaccumulatorFunction
- a side-effect-free function of two argumentspublic String toString()
public final V getPlain()
volatile
.public final void setPlain(V newValue)
newValue
, with memory semantics
of setting as if the variable was declared non-volatile
and non-final
.newValue
- the new valuepublic final V getOpaque()
VarHandle.getOpaque(java.lang.Object...)
.public final void setOpaque(V newValue)
newValue
,
with memory effects as specified by VarHandle.setOpaque(java.lang.Object...)
.newValue
- the new valuepublic final V getAcquire()
VarHandle.getAcquire(java.lang.Object...)
.public final void setRelease(V newValue)
newValue
,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...)
.newValue
- the new valuepublic final V compareAndExchange(V expectedValue, V newValue)
newValue
if the current value,
referred to as the witness value, == expectedValue
,
with memory effects as specified by
VarHandle.compareAndExchange(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuepublic final V compareAndExchangeAcquire(V expectedValue, V newValue)
newValue
if the current value,
referred to as the witness value, == expectedValue
,
with memory effects as specified by
VarHandle.compareAndExchangeAcquire(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuepublic final V compareAndExchangeRelease(V expectedValue, V newValue)
newValue
if the current value,
referred to as the witness value, == expectedValue
,
with memory effects as specified by
VarHandle.compareAndExchangeRelease(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuepublic final boolean weakCompareAndSetVolatile(V expectedValue, V newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by
VarHandle.weakCompareAndSet(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulpublic final boolean weakCompareAndSetAcquire(V expectedValue, V newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by
VarHandle.weakCompareAndSetAcquire(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulpublic final boolean weakCompareAndSetRelease(V expectedValue, V newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by
VarHandle.weakCompareAndSetRelease(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successful Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-internal+0-adhoc.mlchung.jdk9-jdeps