java.util.concurrent.atomic
Class AtomicLong

public class AtomicLong
implements Serializable
A long value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicLong is used in applications such as atomically incremented sequence numbers, and cannot be used as a replacement for a Long . 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
AtomicLong( long initialValue )
Creates a new AtomicLong with the given initial value.
AtomicLong()
Creates a new AtomicLong with initial value 0 .
Method Summary
final long addAndGet( long delta )
Atomically adds the given value to the current value.
final boolean compareAndSet( long expect, long update )
Atomically sets the value to the given updated value if the current value == the expected value.
final long decrementAndGet()
Atomically decrements by one the current value.
double doubleValue()
No description provided.
float floatValue()
No description provided.
final long get()
Gets the current value.
final long getAndAdd( long delta )
Atomically adds the given value to the current value.
final long getAndDecrement()
Atomically decrements by one the current value.
final long getAndIncrement()
Atomically increments by one the current value.
final long getAndSet( long newValue )
Atomically sets to the given value and returns the old value.
final long incrementAndGet()
Atomically increments by one the current value.
int intValue()
No description provided.
final void lazySet( long newValue )
Eventually sets to the given value.
long longValue()
No description provided.
final void set( long newValue )
Sets to the given value.
String toString()
Returns the String representation of the current value.
final boolean weakCompareAndSet( long expect, long update )
Atomically sets the value to the given updated value if the current value == the expected value.
Methods inherited from java.langNumber
AtomicLong
public AtomicLong ( long initialValue )
Creates a new AtomicLong with the given initial value.
Parameters
TypeNameDescription
long initialValue the initial value
Wiki javadoc Use textile entry format.
Add your comments here.
AtomicLong
public AtomicLong ( )
Creates a new AtomicLong with initial value 0 .
Wiki javadoc Use textile entry format.
Add your comments here.
addAndGet
public final long addAndGet ( long delta )
Atomically adds the given value to the current value.
Parameters
TypeNameDescription
long delta the value to add
Wiki javadoc Use textile entry format.
Add your comments here.
compareAndSet
public final boolean compareAndSet ( long expect, long update )
Atomically sets the value to the given updated value if the current value == the expected value.
Parameters
TypeNameDescription
long expect the expected value
long update the new value
Wiki javadoc Use textile entry format.
Add your comments here.
decrementAndGet
public final long 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 long get ( )
Gets the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
getAndAdd
public final long getAndAdd ( long delta )
Atomically adds the given value to the current value.
Parameters
TypeNameDescription
long delta the value to add
Wiki javadoc Use textile entry format.
Add your comments here.
getAndDecrement
public final long getAndDecrement ( )
Atomically decrements by one the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
getAndIncrement
public final long getAndIncrement ( )
Atomically increments by one the current value.
Wiki javadoc Use textile entry format.
Add your comments here.
getAndSet
public final long getAndSet ( long newValue )
Atomically sets to the given value and returns the old value.
Parameters
TypeNameDescription
long newValue the new value
Wiki javadoc Use textile entry format.
Add your comments here.
incrementAndGet
public final long 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 ( long newValue )
Eventually sets to the given value.
Since: 1.6
Parameters
TypeNameDescription
long 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 ( long newValue )
Sets to the given value.
Parameters
TypeNameDescription
long 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 ( long expect, long 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
long expect the expected value
long update the new value
Wiki javadoc Use textile entry format.
Add your comments here.