Class SynchronizedInteger

java.lang.Object
org.jppf.utils.concurrent.SynchronizedInteger

public class SynchronizedInteger extends Object
An integer value on which a set of operations can be performed atomically.
Author:
Laurent Cohen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialize with a value of 0.
    Initialize with the specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    addAndGet(int update)
    Add the specified update and return the new value.
    void
    awaitValue(int target)
    Wait until the value equals the specified target.
    boolean
    compareAndDecrement(ComparisonOperator operator, int expected)
    Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.
    boolean
    compareAndIncrement(ComparisonOperator operator, int expected)
    Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.
    boolean
    compareAndSet(int expected, int update)
    Compare the value with the expected value, and set it to the update value if they are equal.
    boolean
    compareAndSet(ComparisonOperator operator, int expectedUpdate)
    Compare the value with the expected update value using the specified operator, and set it to this update value if the comparison succeeds.
    boolean
    compareAndSet(ComparisonOperator operator, int expected, int update)
    Compare the value with the expected value using the specified operator, and set it to the update value if the comparison succeeds.
    int
    Increment the value.
    int
    get()
    Get the value.
    int
    getAndSet(int newValue)
    Set a new value and return the old value.
    int
    Increment the value.
    int
    Increment the value.
    void
    set(int newValue)
    Set to a new value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SynchronizedInteger

      public SynchronizedInteger()
      Initialize with a value of 0.
    • SynchronizedInteger

      public SynchronizedInteger(int value)
      Initialize with the specified value.
      Parameters:
      value - the initial value.
  • Method Details

    • get

      public int get()
      Get the value.
      Returns:
      the current value.
    • set

      public void set(int newValue)
      Set to a new value.
      Parameters:
      newValue - the value to set.
    • incrementAndGet

      public int incrementAndGet()
      Increment the value.
      Returns:
      the new value.
    • incrementGetAndNotify

      public int incrementGetAndNotify()
      Increment the value.
      Returns:
      the new value.
    • awaitValue

      public void awaitValue(int target)
      Wait until the value equals the specified target.
      Parameters:
      target - the target value to wait for.
    • decrementAndGet

      public int decrementAndGet()
      Increment the value.
      Returns:
      the new value.
    • addAndGet

      public int addAndGet(int update)
      Add the specified update and return the new value.
      Parameters:
      update - the value to add.
      Returns:
      the new value.
    • getAndSet

      public int getAndSet(int newValue)
      Set a new value and return the old value.
      Parameters:
      newValue - the value to set.
      Returns:
      the value before the set.
    • compareAndSet

      public boolean compareAndSet(int expected, int update)
      Compare the value with the expected value, and set it to the update value if they are equal.
      Parameters:
      expected - the expected value.
      update - the new value to set to if the comparison succeeds.
      Returns:
      true if the update was performed, false otherwise.
    • compareAndSet

      public boolean compareAndSet(ComparisonOperator operator, int expected, int update)
      Compare the value with the expected value using the specified operator, and set it to the update value if the comparison succeeds.
      Parameters:
      operator - the comparison operator.
      expected - the expected value.
      update - the new value to set to if the comparison succeeds.
      Returns:
      true if the update was performed, false otherwise.
    • compareAndSet

      public boolean compareAndSet(ComparisonOperator operator, int expectedUpdate)
      Compare the value with the expected update value using the specified operator, and set it to this update value if the comparison succeeds.
      Parameters:
      operator - the comparison operator.
      expectedUpdate - the expected value.
      Returns:
      true if the update was performed, false otherwise.
    • compareAndIncrement

      public boolean compareAndIncrement(ComparisonOperator operator, int expected)
      Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.
      Parameters:
      operator - the comparison operator.
      expected - the expected value.
      Returns:
      true if the update was performed, false otherwise.
    • compareAndDecrement

      public boolean compareAndDecrement(ComparisonOperator operator, int expected)
      Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.
      Parameters:
      operator - the comparison operator.
      expected - the expected value.
      Returns:
      true if the update was performed, false otherwise.