public class AtomicUtils extends Object
| Constructor and Description |
|---|
AtomicUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
atomicMark(T holder,
AtomicIntegerFieldUpdater<T> updater)
Atomically set the field to 1 if the current value is 0.
|
static <T,V> boolean |
atomicSet(T holder,
V value,
AtomicReferenceFieldUpdater<T,V> updater) |
static <T,V> boolean |
atomicSetAndRun(T holder,
V value,
AtomicReferenceFieldUpdater<T,V> updater,
Runnable task) |
static <T> boolean |
isSet(T holder,
AtomicIntegerFieldUpdater<T> updater)
Return true if the field is set to 1, false otherwise.
|
static <T,V> boolean |
isSet(T holder,
AtomicReferenceFieldUpdater<T,V> updater) |
static <T> T |
produceAndSetValue(AtomicReference<T> reference,
Supplier<T> supplier,
Consumer<T> initializer)
Utility to lazily produce and initialize an object stored in an
AtomicReference. |
public static <T,V> boolean atomicSet(T holder,
V value,
AtomicReferenceFieldUpdater<T,V> updater)
public static <T,V> boolean atomicSetAndRun(T holder,
V value,
AtomicReferenceFieldUpdater<T,V> updater,
Runnable task)
public static <T,V> boolean isSet(T holder,
AtomicReferenceFieldUpdater<T,V> updater)
public static <T> boolean atomicMark(T holder,
AtomicIntegerFieldUpdater<T> updater)
true if successful.public static <T> boolean isSet(T holder,
AtomicIntegerFieldUpdater<T> updater)
public static <T> T produceAndSetValue(AtomicReference<T> reference, Supplier<T> supplier, Consumer<T> initializer)
AtomicReference. The
supplier may be invoked multiple times, but the initializer is guaranteed to
only be invoked for the winning value. Note that other threads can see the state of the
object returned by the supplier before the initializer has finished or even
started to be executed.