Interface AtomicLong
- All Known Implementing Classes:
LocalAtomicLong,RemoteAtomicLong
long value that may be updated atomically.
An AtomicLong is used in applications
such as atomically incremented sequence numbers, and cannot be used
as a replacement for a Long.
- Since:
- 21.12
- Author:
- Aleks Seovic 2020.12.03
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classPOF serializer implementation. -
Method Summary
Modifier and TypeMethodDescriptionlongaccumulateAndGet(long lUpdate, Remote.LongBinaryOperator accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.longaccumulateAndGet(long lUpdate, LongBinaryOperator accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.longaddAndGet(long lDelta) Atomically adds the given value to the current value.async()Return non-blocking API for this atomic value.byteReturns the current value of thisAtomicLongas abyteafter a narrowing primitive conversion.longcompareAndExchange(long lExpectedValue, long lNewValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.booleancompareAndSet(long lExpectedValue, long lNewValue) Atomically sets the value tonewValueif the current value== expectedValue.longAtomically decrements the current value.doubleReturns the current value of thisAtomicLongas adoubleafter a widening primitive conversion.floatReturns the current value of thisAtomicLongas afloatafter a widening primitive conversion.longget()Returns the current value.longgetAndAccumulate(long lUpdate, Remote.LongBinaryOperator accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.longgetAndAccumulate(long lUpdate, LongBinaryOperator accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.longgetAndAdd(long lDelta) Atomically adds the given value to the current value.longAtomically decrements the current value.longAtomically increments the current value.longgetAndSet(long lNewValue) Atomically sets the value tonewValueand returns the old value.longgetAndUpdate(Remote.LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.longgetAndUpdate(LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.longAtomically increments the current value.intintValue()Returns the current value of thisAtomicLongas anintafter a narrowing primitive conversion.longReturns the current value of thisAtomicLongas along.voidset(long lNewValue) Sets the value tonewValue.shortReturns the current value of thisAtomicLongas ashortafter a narrowing primitive conversion.longupdateAndGet(Remote.LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.longupdateAndGet(LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.
-
Method Details
-
async
AsyncAtomicLong async()Return non-blocking API for this atomic value.- Returns:
- non-blocking API for this atomic value
-
get
long get()Returns the current value.- Returns:
- the current value
-
set
void set(long lNewValue) Sets the value tonewValue.- Parameters:
lNewValue- the new value
-
getAndSet
long getAndSet(long lNewValue) Atomically sets the value tonewValueand returns the old value.- Parameters:
lNewValue- the new value- Returns:
- the previous value
-
compareAndSet
boolean compareAndSet(long lExpectedValue, long lNewValue) Atomically sets the value tonewValueif the current value== expectedValue.- Parameters:
lExpectedValue- the expected valuelNewValue- the new value- Returns:
trueif successful. False return indicates that the actual value was not equal to the expected value.
-
getAndIncrement
long getAndIncrement()Atomically increments the current value.Equivalent to
getAndAdd(1).- Returns:
- the previous value
-
getAndDecrement
long getAndDecrement()Atomically decrements the current value.Equivalent to
getAndAdd(-1).- Returns:
- the previous value
-
getAndAdd
long getAndAdd(long lDelta) Atomically adds the given value to the current value.- Parameters:
lDelta- the value to add- Returns:
- the previous value
-
incrementAndGet
long incrementAndGet()Atomically increments the current value.Equivalent to
addAndGet(1).- Returns:
- the updated value
-
decrementAndGet
long decrementAndGet()Atomically decrements the current value.Equivalent to
addAndGet(-1).- Returns:
- the updated value
-
addAndGet
long addAndGet(long lDelta) Atomically adds the given value to the current value.- Parameters:
lDelta- the value to add- Returns:
- the updated value
-
getAndUpdate
Atomically updates the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
Atomically updates the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
Atomically updates the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
Atomically updates the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.The function should beside-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.The function should beside-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
long compareAndExchange(long lExpectedValue, long lNewValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.- Parameters:
lExpectedValue- the expected valuelNewValue- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
intValue
int intValue()Returns the current value of thisAtomicLongas anintafter a narrowing primitive conversion.- Returns:
- the numeric value represented by this object after conversion
to type
int
-
longValue
long longValue()Returns the current value of thisAtomicLongas along.- Returns:
- the numeric value represented by this object
-
floatValue
float floatValue()Returns the current value of thisAtomicLongas afloatafter a widening primitive conversion.- Returns:
- the numeric value represented by this object after conversion
to type
float
-
doubleValue
double doubleValue()Returns the current value of thisAtomicLongas adoubleafter a widening primitive conversion.- Returns:
- the numeric value represented by this object after conversion
to type
double
-
byteValue
byte byteValue()Returns the current value of thisAtomicLongas abyteafter a narrowing primitive conversion.- Returns:
- the numeric value represented by this object after conversion
to type
byte
-
shortValue
short shortValue()Returns the current value of thisAtomicLongas ashortafter a narrowing primitive conversion.- Returns:
- the numeric value represented by this object after conversion
to type
short
-