Package org.jppf.utils.concurrent
Class SynchronizedLong
java.lang.Object
org.jppf.utils.concurrent.SynchronizedLong
A long value on which a set of operations can be performed atomically.
- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize with a value of 0.SynchronizedLong(long value) Initialize with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionlongaddAndGet(long update) Add the specified update and return the new value.booleancompareAndRun(ComparisonOperator operator, long expected, Runnable action) Compare the value with the expected value, and run the action if they are equal.booleancompareAndSet(long expected, long update) Compare the value witht he expected value, and set it to the update value if they are equal.booleancompareAndSet(ComparisonOperator operator, long expectedUpdate) Compare the value with the expected update value using the specified operator, and set it to this update value if the comparison succeeds.booleancompareAndSet(ComparisonOperator operator, long expected, long update) Compare the value with the expected value using the specified operator, and set it to the update value if the comparison succeeds.longIncrement the value.longget()Get the value.longgetAndSet(long newValue) Set a new value and return the old value.longIncrement the value.booleanrunIfBetween(long lower, long upper, Runnable action) Run the specified action if the value is within the specified bounds.booleanrunIfNotBetween(long lower, long upper, Runnable action) Run the specified action if the value is outside the specified bounds.voidset(long newValue) Set to a new value.
-
Constructor Details
-
SynchronizedLong
public SynchronizedLong()Initialize with a value of 0. -
SynchronizedLong
public SynchronizedLong(long value) Initialize with the specified value.- Parameters:
value- the initial value.
-
-
Method Details
-
get
public long get()Get the value.- Returns:
- the current value.
-
set
public void set(long newValue) Set to a new value.- Parameters:
newValue- the value to set.
-
incrementAndGet
public long incrementAndGet()Increment the value.- Returns:
- the new value.
-
decrementAndGet
public long decrementAndGet()Increment the value.- Returns:
- the new value.
-
addAndGet
public long addAndGet(long update) Add the specified update and return the new value.- Parameters:
update- the value to add.- Returns:
- the new value.
-
getAndSet
public long getAndSet(long 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(long expected, long update) Compare the value witht he 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.
-
compareAndSet
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:
trueif the update was performed,falseotherwise.
-
compareAndSet
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:
trueif the update was performed,falseotherwise.
-
compareAndRun
Compare the value with the expected value, and run the action if they are equal.- Parameters:
operator- the comparison operator.expected- the expected value.action- the action to run if the comparison succeeds.- Returns:
trueif the update was performed,falseotherwise.
-
runIfBetween
Run the specified action if the value is within the specified bounds.- Parameters:
lower- the lower bound of the between comparison.upper- the upper bound of the between comparison.action- the action to run if the comparison succeeds.- Returns:
trueif the update was performed,falseotherwise.
-
runIfNotBetween
Run the specified action if the value is outside the specified bounds.- Parameters:
lower- the lower bound of the between comparison.upper- the upper bound of the between comparison.action- the action to run if the comparison succeeds.- Returns:
trueif the update was performed,falseotherwise.
-