Package org.jppf.utils.concurrent
Class SynchronizedBoolean
java.lang.Object
org.jppf.utils.concurrent.SynchronizedBoolean
A boolean value on which a set of operations can be performed atomically.
- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize with the value ste tofalse.SynchronizedBoolean(boolean value) Iinitialize witht he specified value. -
Method Summary
Modifier and TypeMethodDescriptionbooleancompareAndRun(boolean expected, Runnable action) Run an action if the value is the expected one.booleancompareAndSet(boolean expected, boolean update) Compare the value with the expected value, and set it to the update value if they are equal.booleanget()booleangetAndSet(boolean newValue) Set a new value and return the old value.voidRun an action while synchronizing on this object.voidset(boolean newValue) Set a new value.
-
Constructor Details
-
SynchronizedBoolean
public SynchronizedBoolean()Initialize with the value ste tofalse. -
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:
trueif the update was performed,falseotherwise.
-
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
Run an action if the value is the expected one.- Parameters:
expected- the expected value.action- the action to run.- Returns:
trueif the update was performed,falseotherwise.
-
run
Run an action while synchronizing on this object.- Parameters:
action- the action to run.
-