public class AtomicInt
extends java.lang.Object
An atomic (thread-safe, mutable) ValueType
value.
Constructor and Description |
---|
AtomicInt() |
Modifier and Type | Method and Description |
---|---|
boolean |
compareAndSet(int expect,
int update)
Change the current value if it matches an expected value.
|
int |
get()
Return the current value.
|
int |
getAndSet(int newValue)
Get and set the current value.
|
void |
set(int newValue)
Set the current value.
|
java.lang.String |
toString() |
public boolean compareAndSet(int expect, int update)
Change the current value if it matches an expected value. Otherwise leave the value unchanged.
expect
- Expected value.update
- New value.true
if the value was changed, false
otherwise.public int get()
Return the current value.
public int getAndSet(int newValue)
Get and set the current value.
newValue
- New value.public void set(int newValue)
Set the current value.
newValue
- New value.public java.lang.String toString()
toString
in class java.lang.Object