Class AtomicDouble

    • Constructor Summary

      Constructors

      Constructor and Description
      AtomicDouble()
      Creates a new AtomicDouble with initial value 0.0.
      AtomicDouble(double initialValue)
      Creates a new AtomicDouble with the given initial value.
    • Method Summary

      Modifier and Type Method and Description
      double addAndGet(double delta)
      Atomically adds the given value to the current value.
      boolean compareAndSet(double expect, double update)
      Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value.
      double doubleValue()
      Returns the value of this AtomicDouble as a double.
      float floatValue()
      Returns the value of this AtomicDouble as a float after a narrowing primitive conversion.
      double get()
      Gets the current value.
      double getAndAdd(double delta)
      Atomically adds the given value to the current value.
      double getAndSet(double newValue)
      Atomically sets to the given value and returns the old value.
      int intValue()
      Returns the value of this AtomicDouble as an int after a narrowing primitive conversion.
      void lazySet(double newValue)
      Eventually sets to the given value.
      long longValue()
      Returns the value of this AtomicDouble as a long after a narrowing primitive conversion.
      void set(double newValue)
      Sets to the given value.
      String toString()
      Returns the String representation of the current value.
      boolean weakCompareAndSet(double expect, double update)
      Atomically sets the value to the given updated value if the current value is bitwise equal to the expected value.
    • Constructor Detail

      • AtomicDouble

        public AtomicDouble(double initialValue)
        Creates a new AtomicDouble with the given initial value.
        Parameters:
        initialValue - the initial value
      • AtomicDouble

        public AtomicDouble()
        Creates a new AtomicDouble with initial value 0.0.
    • Method Detail

      • get

        public final double get()
        Gets the current value.
        Returns:
        the current value
      • set

        public final void set(double newValue)
        Sets to the given value.
        Parameters:
        newValue - the new value
      • lazySet

        public final void lazySet(double newValue)
        Eventually sets to the given value.
        Parameters:
        newValue - the new value
      • getAndSet

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

        public final boolean compareAndSet(double expect,
                                           double update)
        Atomically sets the value to the given updated value if the current value is bitwise equal to 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 bitwise equal to the expected value.
      • weakCompareAndSet

        public final boolean weakCompareAndSet(double expect,
                                               double update)
        Atomically sets the value to the given updated value if the current value is bitwise equal to 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
      • getAndAdd

        public final double getAndAdd(double delta)
        Atomically adds the given value to the current value.
        Parameters:
        delta - the value to add
        Returns:
        the previous value
      • addAndGet

        public final double addAndGet(double delta)
        Atomically adds the given value to the current value.
        Parameters:
        delta - the value to add
        Returns:
        the updated value
      • 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 of this AtomicDouble as an int after a narrowing primitive conversion.
      • longValue

        public long longValue()
        Returns the value of this AtomicDouble as a long after a narrowing primitive conversion.
      • floatValue

        public float floatValue()
        Returns the value of this AtomicDouble as a float after a narrowing primitive conversion.
      • doubleValue

        public double doubleValue()
        Returns the value of this AtomicDouble as a double.