Class MonotonicAtomicLong

  • All Implemented Interfaces:
    Serializable

    public class MonotonicAtomicLong
    extends AtomicLong
    Enriches AtomicLong with methods that allow it to be updated only if doing so would increase (or decrease) its value.
    Author:
    Boris Grozev
    See Also:
    Serialized Form
    • Constructor Detail

      • MonotonicAtomicLong

        public MonotonicAtomicLong()
    • Method Detail

      • increase

        public long increase​(long newValue)
        Updates the value of this AtomicLong if it is bigger than the current value, and returns the actual new value. Implemented this way (without AtomicLong.updateAndGet(java.util.function.LongUnaryOperator)) for compatibility with java 1.7.
        Parameters:
        newValue - the new value to try to set.
        Returns:
        the actual new value whuch may be greater than or equal to newValue.
      • decrease

        public long decrease​(long newValue)
        Updates the value of this AtomicLong if it is smaller than the current value, and returns the actual new value. Implemented this way (without AtomicLong.updateAndGet(java.util.function.LongUnaryOperator)) for compatibility with java 1.7.
        Parameters:
        newValue - the value to try to set.
        Returns:
        the actual new value which may be less than or equal to newValue.