Class PaddedAtomicLong

All Implemented Interfaces:
Serializable

public class PaddedAtomicLong extends PaddedAtomicLongL2Pad
A padded version of the AtomicLong.
See Also:
  • Constructor Details

    • PaddedAtomicLong

      public PaddedAtomicLong()
      Creates a new PaddedAtomicLong with initial value 0.
    • PaddedAtomicLong

      public PaddedAtomicLong(long initialValue)
      Creates a new PaddedAtomicLong with the given initial value.
      Parameters:
      initialValue - the initial value
  • Method Details

    • get

      public long get()
      Gets the current value.
      Returns:
      the current value
      See Also:
    • set

      public void set(long newValue)
      Sets to the given value.
      Parameters:
      newValue - the new value
      See Also:
    • lazySet

      public void lazySet(long newValue)
      Eventually sets to the given value.
      Parameters:
      newValue - the new value
      See Also:
    • getAndSet

      public long getAndSet(long newValue)
      Atomically sets to the given value and returns the old value.
      Parameters:
      newValue - the new value
      Returns:
      the previous value
      See Also:
    • compareAndSet

      public boolean compareAndSet(long expect, long update)
      Atomically sets the value to the given updated value if the current value == the expected value.
      Parameters:
      expect - the expected value
      update - the new value
      Returns:
      true if successful. False return indicates that the actual value was not equal to the expected value.
      See Also:
    • weakCompareAndSet

      public boolean weakCompareAndSet(long expect, long update)
      Atomically sets the value to the given updated value if the current value == the expected value.

      May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.

      Parameters:
      expect - the expected value
      update - the new value
      Returns:
      true if successful
      See Also:
    • getAndIncrement

      public long getAndIncrement()
      Atomically increments the current value by 1.
      Returns:
      the previous value
      See Also:
    • getAndDecrement

      public long getAndDecrement()
      Atomically decrements the current value by 1.
      Returns:
      the previous value
      See Also:
    • getAndAdd

      public long getAndAdd(long delta)
      Atomically adds to the current value the given value.
      Parameters:
      delta - the value to add
      Returns:
      the previous value
      See Also:
    • incrementAndGet

      public long incrementAndGet()
      Atomically increments the current value by one.
      Returns:
      the updated value
      See Also:
    • decrementAndGet

      public long decrementAndGet()
      Atomically decrements the current value by one.
      Returns:
      the updated value
      See Also:
    • addAndGet

      public long addAndGet(long delta)
      Atomically adds to current value te given value.
      Parameters:
      delta - the value to add
      Returns:
      the updated value
      See Also:
    • getAndUpdate

      public long getAndUpdate(LongUnaryOperator updateFunction)
      Atomically updates the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the previous value
      See Also:
    • updateAndGet

      public long updateAndGet(LongUnaryOperator updateFunction)
      Atomically updates the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the updated value
      See Also:
    • getAndAccumulate

      public long getAndAccumulate(long v, LongBinaryOperator f)
      Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
      Parameters:
      v - the update value
      f - a side-effect-free function of two arguments
      Returns:
      the previous value
      See Also:
    • accumulateAndGet

      public long accumulateAndGet(long x, LongBinaryOperator f)
    • toString

      public String toString()
      Returns the String representation of the current value.
      Overrides:
      toString in class Object
      Returns:
      the String representation of the current value
    • intValue

      public int intValue()
      Returns the value as an int.
      Specified by:
      intValue in class Number
      See Also:
    • longValue

      public long longValue()
      Returns the value as a long.
      Specified by:
      longValue in class Number
      See Also:
    • floatValue

      public float floatValue()
      Returns the value of a float.
      Specified by:
      floatValue in class Number
      See Also:
    • doubleValue

      public double doubleValue()
      Returns the value of a double.
      Specified by:
      doubleValue in class Number
      See Also: