java.util.concurrent.atomic
Class AtomicInteger

public class AtomicInteger
implements Serializable
An int value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicInteger is used in applications such as atomically incremented counters, and cannot be used as a replacement for an Integer . However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.
Since1.5
VersionNot specified.
AuthorDoug Lea
Wiki javadoc Use textile entry format.
Add your comments here.
Constructor Summary
AtomicInteger( int initialValue )
Creates a new AtomicInteger with the given initial value.
AtomicInteger()
Creates a new AtomicInteger with initial value 0 .
Method Summary
final int addAndGet( int delta )
Atomically adds the given value to the current value.
final boolean compareAndSet( int expect, int update )
Atomically sets the value to the given updated value if the current value == the expected value.
final int decrementAndGet()
Atomically decrements by one the current value.
double doubleValue()
No description provided.
float floatValue()
No description provided.
final int get()
Gets the current value.
final int getAndAdd( int delta )
Atomically adds the given value to the current value.
final int getAndDecrement()
Atomically decrements by one the current value.
final int getAndIncrement()
Atomically increments by one the current value.
final int getAndSet( int newValue )
Atomically sets to the given value and returns the old value.
final int incrementAndGet()
Atomically increments by one the current value.
int intValue()
No description provided.
final void lazySet( int newValue )
Eventually sets to the given value.
long longValue()
No description provided.
final void set( int newValue )
Sets to the given value.
String toString()
Returns the String representation of the current value.
final boolean weakCompareAndSet( int expect, int update )
Atomically sets the value to the given updated value if the current value == the expected value.
Methods inherited from java.langNumber
AtomicInteger
public AtomicInteger ( int initialValue )
Creates a new AtomicInteger with the given initial value.
Parameters
TypeNameDescription
int initialValue the initial value
Wiki javadoc Use textile entry format.
Add your comments here.
AtomicInteger
public AtomicInteger ( )
Creates a new AtomicInteger with initial value 0 .
Wiki javadoc Use textile entry format.
Add your comments here.
addAndGet
public final int addAndGet ( int delta )
Atomically adds the given value to the current value.
Parameters
TypeNameDescription
int delta the value to add
Wiki javadoc Use textile entry format.
Add your comments here.
compareAndSet
public final boolean compareAndSet ( int expect, int update )
Atomically sets the value to the given updated value if the current value == the expected value.
Parameters
TypeNameDescription
int expect the expected value
int update the new value
Wiki javadoc Use textile entry format.
Add your comments here.
decrementAndGet
public final int decrementAndGet ( )
Atomically decrements by one the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
doubleValue
public double doubleValue ( )
No description provided.
Overrides method in Number
Wiki javadoc Use textile entry format.
Add your comments here.
floatValue
public float floatValue ( )
No description provided.
Overrides method in Number
Wiki javadoc Use textile entry format.
Add your comments here.
get
public final int get ( )
Gets the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
getAndAdd
public final int getAndAdd ( int delta )
Atomically adds the given value to the current value.
Parameters
TypeNameDescription
int delta the value to add
Wiki javadoc Use textile entry format.
Add your comments here.
getAndDecrement
public final int getAndDecrement ( )
Atomically decrements by one the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
getAndIncrement
public final int getAndIncrement ( )
Atomically increments by one the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
getAndSet
public final int getAndSet ( int newValue )
Atomically sets to the given value and returns the old value.
Parameters
TypeNameDescription
int newValue the new value
Wiki javadoc Use textile entry format.
Add your comments here.
incrementAndGet
public final int incrementAndGet ( )
Atomically increments by one the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
intValue
public int intValue ( )
No description provided.
Overrides method in Number
Wiki javadoc Use textile entry format.
Add your comments here.
lazySet
public final void lazySet ( int newValue )
Eventually sets to the given value.
Since: 1.6
Parameters
TypeNameDescription
int newValue the new value
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
longValue
public long longValue ( )
No description provided.
Overrides method in Number
Wiki javadoc Use textile entry format.
Add your comments here.
set
public final void set ( int newValue )
Sets to the given value.
Parameters
TypeNameDescription
int newValue the new value
Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
toString
public String toString ( )
Returns the String representation of the current value.
Overrides method in Object
Wiki javadoc Use textile entry format.
Add your comments here.
weakCompareAndSet
public final boolean weakCompareAndSet ( int expect, int update )
Atomically sets the value to the given updated value if the current value == the expected value.

May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet .

Parameters
TypeNameDescription
int expect the expected value
int update the new value
Wiki javadoc Use textile entry format.
Add your comments here.