Class SynchronizedBoolean

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

public class SynchronizedBoolean extends Object
A boolean value on which a set of operations can be performed atomically.
Author:
Laurent Cohen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialize with the value ste to false.
    SynchronizedBoolean(boolean value)
    Iinitialize witht he specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    compareAndRun(boolean expected, Runnable action)
    Run an action if the value is the expected one.
    boolean
    compareAndSet(boolean expected, boolean update)
    Compare the value with the expected value, and set it to the update value if they are equal.
    boolean
    get()
     
    boolean
    getAndSet(boolean newValue)
    Set a new value and return the old value.
    void
    run(Runnable action)
    Run an action while synchronizing on this object.
    void
    set(boolean newValue)
    Set a new value.

    Methods inherited from class java.lang.Object

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

    • SynchronizedBoolean

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

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

    • get

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

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

      public boolean compareAndSet(boolean expected, boolean 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 boolean getAndSet(boolean 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(boolean expected, Runnable action)
      Run an action if the value is the expected one.
      Parameters:
      expected - the expected value.
      action - the action to run.
      Returns:
      true if the update was performed, false otherwise.
    • run

      public void run(Runnable action)
      Run an action while synchronizing on this object.
      Parameters:
      action - the action to run.