Package org.jppf.utils.concurrent
Class SynchronizedInteger
java.lang.Object
org.jppf.utils.concurrent.SynchronizedInteger
An integer value on which a set of operations can be performed atomically.
- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize with a value of 0.SynchronizedInteger(int value) Initialize with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionintaddAndGet(int update) Add the specified update and return the new value.voidawaitValue(int target) Wait until the value equals the specified target.booleancompareAndDecrement(ComparisonOperator operator, int expected) Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.booleancompareAndIncrement(ComparisonOperator operator, int expected) Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.booleancompareAndSet(int expected, int update) Compare the value with the expected value, and set it to the update value if they are equal.booleancompareAndSet(ComparisonOperator operator, int 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, int expected, int update) Compare the value with the expected value using the specified operator, and set it to the update value if the comparison succeeds.intIncrement the value.intget()Get the value.intgetAndSet(int newValue) Set a new value and return the old value.intIncrement the value.intIncrement the value.voidset(int newValue) Set to a new value.
-
Constructor Details
-
SynchronizedInteger
public SynchronizedInteger()Initialize with a value of 0. -
SynchronizedInteger
public SynchronizedInteger(int value) Initialize with the specified value.- Parameters:
value- the initial value.
-
-
Method Details
-
get
public int get()Get the value.- Returns:
- the current value.
-
set
public void set(int newValue) Set to a new value.- Parameters:
newValue- the value to set.
-
incrementAndGet
public int incrementAndGet()Increment the value.- Returns:
- the new value.
-
incrementGetAndNotify
public int incrementGetAndNotify()Increment the value.- Returns:
- the new value.
-
awaitValue
public void awaitValue(int target) Wait until the value equals the specified target.- Parameters:
target- the target value to wait for.
-
decrementAndGet
public int decrementAndGet()Increment the value.- Returns:
- the new value.
-
addAndGet
public int addAndGet(int update) Add the specified update and return the new value.- Parameters:
update- the value to add.- Returns:
- the new value.
-
getAndSet
public int getAndSet(int 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(int expected, int 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.
-
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.
-
compareAndIncrement
Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.- Parameters:
operator- the comparison operator.expected- the expected value.- Returns:
trueif the update was performed,falseotherwise.
-
compareAndDecrement
Compare the value with the expected value using the specified operator, and increment it if the comparison succeeds.- Parameters:
operator- the comparison operator.expected- the expected value.- Returns:
trueif the update was performed,falseotherwise.
-