Package org.jppf.utils.concurrent
Class SynchronizedReference<T>
java.lang.Object
org.jppf.utils.concurrent.SynchronizedReference<T>
- Type Parameters:
T- thr type of the refered object.
An
Object value on which a set of operations can be performed atomically.- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize with the value ste tofalse.SynchronizedReference(T value) Iinitialize witht he specified value. -
Method Summary
Modifier and TypeMethodDescriptionbooleancompareAndRun(T expected, Runnable action) Run an action if the value is the expected one.booleancompareAndSet(T expected, T update) Compare the value with the expected value, and set it to the update value if they are equal.get()Set a new value and return the old value.voidSet a new value.booleansetIfDifferent(T newValue) Set a new value if it is different from the current value.
-
Constructor Details
-
SynchronizedReference
public SynchronizedReference()Initialize with the value ste tofalse. -
SynchronizedReference
Iinitialize witht he specified value.- Parameters:
value- the initial value.
-
-
Method Details
-
get
- Returns:
- the value of this boolan.
-
set
Set a new value.- Parameters:
newValue- the value to set.
-
setIfDifferent
Set a new value if it is different from the current value.- Parameters:
newValue- the value to set.- Returns:
trueif the value was changed,falseotherwise.
-
compareAndSet
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
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 aciton to run.- Returns:
trueif the update was performed,falseotherwise.
-