Package org.stianloader.mrjmania
Class MRJAtomics
java.lang.Object
org.stianloader.mrjmania.MRJAtomics
Polyfills related to classes like
AtomicInteger, AtomicReference,
etc. However, the polyfill themselves are probably the exact opposite of what
these classes usually provide.-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetPlain(@NotNull AtomicInteger atomic) Get the value of anAtomicInteger, with plain access if possible (J9+), otherwise be stricter from a thread-safety standpoint.static <@Nullable V>
VgetPlain(@NotNull AtomicReference<@Nullable V> atomic) Get the value of anAtomicReference, with plain access if possible (J9+), otherwise be stricter.static voidsetPlain(@NotNull AtomicInteger atomic, int value) Sets the value of anAtomicIntegerusing a plain write if possible (J9+), otherwise be stricter from a thread-safety standpoint.static <@Nullable V>
voidsetPlain(@NotNull AtomicReference<@Nullable V> atomic, @Nullable V value) Sets the value of anAtomicReferenceusing a plain write if possible (J9+), otherwise be stricter from a thread-safety standpoint.
-
Method Details
-
getPlain
Get the value of anAtomicInteger, with plain access if possible (J9+), otherwise be stricter from a thread-safety standpoint.- Parameters:
atomic- The atomic object to pull the value from.- Returns:
- The value stored in the
AtomicInteger, as per plain access (or volatile read, if plain access is not available).
-
getPlain
@Contract(pure=true) public static <@Nullable V> V getPlain(@NotNull @NotNull AtomicReference<@Nullable V> atomic) Get the value of anAtomicReference, with plain access if possible (J9+), otherwise be stricter.- Type Parameters:
V- The type of the reference value stored by theAtomicReference.- Parameters:
atomic- The atomic object to pull the value from.- Returns:
- The value stored in the
AtomicReference, as per plain access (or volatile read, if plain access is not available).
-
setPlain
@Contract(pure=false, mutates="param1") public static void setPlain(@NotNull @NotNull AtomicInteger atomic, int value) Sets the value of anAtomicIntegerusing a plain write if possible (J9+), otherwise be stricter from a thread-safety standpoint.A plain write might never get updated to threads, making this method highly unwise to use in multi-threaded environments, unless stale reads are not a concern. However, it is possible that other threads might see the updated value, so it should not be expected that plain writes are thread-local. Generally, given enough time, changes will be visible to other threads.
- Parameters:
atomic- TheAtomicIntegerto set the value of.value- The value.
-
setPlain
@Contract(pure=false, mutates="param1") public static <@Nullable V> void setPlain(@NotNull @NotNull AtomicReference<@Nullable V> atomic, @Nullable V value) Sets the value of anAtomicReferenceusing a plain write if possible (J9+), otherwise be stricter from a thread-safety standpoint.A plain write might never get updated to threads, making this method highly unwise to use in multi-threaded environments, unless stale reads are not a concern. However, it is possible that other threads might see the updated value, so it should not be expected that plain writes are thread-local. Generally, given enough time, changes will be visible to other threads.
- Type Parameters:
V- The type of the reference value stored by theAtomicReference.- Parameters:
atomic- TheAtomicReferenceto set the value of.value- The value, may be null.
-