Class SynchronizedReference<T>

java.lang.Object
org.jppf.utils.concurrent.SynchronizedReference<T>
Type Parameters:
T - thr type of the refered object.

public class SynchronizedReference<T> extends Object
An Object value on which a set of operations can be performed atomically.
Author:
Laurent Cohen
  • Constructor Details

    • SynchronizedReference

      public SynchronizedReference()
      Initialize with the value ste to false.
    • SynchronizedReference

      public SynchronizedReference(T value)
      Iinitialize witht he specified value.
      Parameters:
      value - the initial value.
  • Method Details

    • get

      public T get()
      Returns:
      the value of this boolan.
    • set

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

      public boolean setIfDifferent(T newValue)
      Set a new value if it is different from the current value.
      Parameters:
      newValue - the value to set.
      Returns:
      true if the value was changed, false otherwise.
    • compareAndSet

      public boolean compareAndSet(T expected, T 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.
    • getAndSet

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

      public boolean compareAndRun(T expected, Runnable action)
      Run an action if the value is the expected one.
      Parameters:
      expected - the expected value.
      action - the aciton to run.
      Returns:
      true if the update was performed, false otherwise.