Class MRJAtomics

java.lang.Object
org.stianloader.mrjmania.MRJAtomics

public class MRJAtomics extends Object
Polyfills related to classes like AtomicInteger, AtomicReference, etc. However, the polyfill themselves are probably the exact opposite of what these classes usually provide.
  • Method Details

    • getPlain

      @Contract(pure=true) public static int getPlain(@NotNull @NotNull AtomicInteger atomic)
      Get the value of an AtomicInteger, 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 an AtomicReference, with plain access if possible (J9+), otherwise be stricter.
      Type Parameters:
      V - The type of the reference value stored by the AtomicReference.
      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 an AtomicInteger using 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 - The AtomicInteger to 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 an AtomicReference using 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 the AtomicReference.
      Parameters:
      atomic - The AtomicReference to set the value of.
      value - The value, may be null.