public class AtomicUtils extends Object
| Constructor and Description |
|---|
AtomicUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
atomicMark(AtomicBoolean flag)
Atomically sets the value to
true if the current value == false. |
static <T> boolean |
atomicMark(T holder,
AtomicIntegerFieldUpdater<T> updater)
Atomically set the field to 1 if the current value is 0.
|
static boolean |
atomicMarkAndRun(AtomicBoolean flag,
Runnable task)
Atomically sets the value to
true if the current value == false. |
static <T> boolean |
atomicMarkAndRun(T holder,
AtomicIntegerFieldUpdater<T> updater,
Runnable task)
Atomically set the field to 1 if the current value is 0.
|
static <T> boolean |
isSet(T holder,
AtomicIntegerFieldUpdater<T> updater)
Return true if the field is set to 1, false otherwise.
|
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> boolean atomicMark(T holder,
AtomicIntegerFieldUpdater<T> updater)
true if successful.public static <T> boolean atomicMarkAndRun(T holder,
AtomicIntegerFieldUpdater<T> updater,
Runnable task)
true if successful.public static <T> boolean isSet(T holder,
AtomicIntegerFieldUpdater<T> updater)
public static boolean atomicMark(AtomicBoolean flag)
true if the current value == false.true if successful.public static boolean atomicMarkAndRun(AtomicBoolean flag, Runnable task)
true if the current value == false. If
successful, execute the task.true if successful.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.