java.util.concurrent.atomic
Class AtomicLong

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.Number sample code for java.lang.Number definition code for java.lang.Number 
      extended by java.util.concurrent.atomic.AtomicLong
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class AtomicLong
extends Number sample code for java.lang.Number definition code for java.lang.Number
implements Serializable sample code for java.io.Serializable definition code for java.io.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 sample code for java.lang.Long definition code for java.lang.Long . However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.

Since:
1.5
See Also:
Serialized Form

Constructor Summary
AtomicLong sample code for java.util.concurrent.atomic.AtomicLong.AtomicLong() definition code for java.util.concurrent.atomic.AtomicLong.AtomicLong() ()
          Create a new AtomicLong with initial value 0.
AtomicLong sample code for java.util.concurrent.atomic.AtomicLong.AtomicLong(long) definition code for java.util.concurrent.atomic.AtomicLong.AtomicLong(long) (long initialValue)
          Create a new AtomicLong with the given initial value.
 
Method Summary
 long addAndGet sample code for java.util.concurrent.atomic.AtomicLong.addAndGet(long) definition code for java.util.concurrent.atomic.AtomicLong.addAndGet(long) (long delta)
          Atomically add the given value to current value.
 boolean compareAndSet sample code for java.util.concurrent.atomic.AtomicLong.compareAndSet(long, long) definition code for java.util.concurrent.atomic.AtomicLong.compareAndSet(long, long) (long expect, long update)
          Atomically set the value to the given updated value if the current value == the expected value.
 long decrementAndGet sample code for java.util.concurrent.atomic.AtomicLong.decrementAndGet() definition code for java.util.concurrent.atomic.AtomicLong.decrementAndGet() ()
          Atomically decrement by one the current value.
 double doubleValue sample code for java.util.concurrent.atomic.AtomicLong.doubleValue() definition code for java.util.concurrent.atomic.AtomicLong.doubleValue() ()
          Returns the value of the specified number as a double.
 float floatValue sample code for java.util.concurrent.atomic.AtomicLong.floatValue() definition code for java.util.concurrent.atomic.AtomicLong.floatValue() ()
          Returns the value of the specified number as a float.
 long get sample code for java.util.concurrent.atomic.AtomicLong.get() definition code for java.util.concurrent.atomic.AtomicLong.get() ()
          Get the current value.
 long getAndAdd sample code for java.util.concurrent.atomic.AtomicLong.getAndAdd(long) definition code for java.util.concurrent.atomic.AtomicLong.getAndAdd(long) (long delta)
          Atomically add the given value to current value.
 long getAndDecrement sample code for java.util.concurrent.atomic.AtomicLong.getAndDecrement() definition code for java.util.concurrent.atomic.AtomicLong.getAndDecrement() ()
          Atomically decrement by one the current value.
 long getAndIncrement sample code for java.util.concurrent.atomic.AtomicLong.getAndIncrement() definition code for java.util.concurrent.atomic.AtomicLong.getAndIncrement() ()
          Atomically increment by one the current value.
 long getAndSet sample code for java.util.concurrent.atomic.AtomicLong.getAndSet(long) definition code for java.util.concurrent.atomic.AtomicLong.getAndSet(long) (long newValue)
          Set to the give value and return the old value.
 long incrementAndGet sample code for java.util.concurrent.atomic.AtomicLong.incrementAndGet() definition code for java.util.concurrent.atomic.AtomicLong.incrementAndGet() ()
          Atomically increment by one the current value.
 int intValue sample code for java.util.concurrent.atomic.AtomicLong.intValue() definition code for java.util.concurrent.atomic.AtomicLong.intValue() ()
          Returns the value of the specified number as an int.
 long longValue sample code for java.util.concurrent.atomic.AtomicLong.longValue() definition code for java.util.concurrent.atomic.AtomicLong.longValue() ()
          Returns the value of the specified number as a long.
 void set sample code for java.util.concurrent.atomic.AtomicLong.set(long) definition code for java.util.concurrent.atomic.AtomicLong.set(long) (long newValue)
          Set to the given value.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.util.concurrent.atomic.AtomicLong.toString() definition code for java.util.concurrent.atomic.AtomicLong.toString() ()
          Returns the String representation of the current value.
 boolean weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicLong.weakCompareAndSet(long, long) definition code for java.util.concurrent.atomic.AtomicLong.weakCompareAndSet(long, long) (long expect, long update)
          Atomically set the value to the given updated value if the current value == the expected value.
 
Methods inherited from class java.lang.Number sample code for java.lang.Number definition code for java.lang.Number
byteValue sample code for java.lang.Number.byteValue() definition code for java.lang.Number.byteValue() , shortValue sample code for java.lang.Number.shortValue() definition code for java.lang.Number.shortValue()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

AtomicLong sample code for java.util.concurrent.atomic.AtomicLong(long) definition code for java.util.concurrent.atomic.AtomicLong(long)

public AtomicLong(long initialValue)
Create a new AtomicLong with the given initial value.

Parameters:
initialValue - the initial value

AtomicLong sample code for java.util.concurrent.atomic.AtomicLong() definition code for java.util.concurrent.atomic.AtomicLong()

public AtomicLong()
Create a new AtomicLong with initial value 0.

Method Detail

get sample code for java.util.concurrent.atomic.AtomicLong.get() definition code for java.util.concurrent.atomic.AtomicLong.get()

public final long get()
Get the current value.

Returns:
the current value

set sample code for java.util.concurrent.atomic.AtomicLong.set(long) definition code for java.util.concurrent.atomic.AtomicLong.set(long)

public final void set(long newValue)
Set to the given value.

Parameters:
newValue - the new value

getAndSet sample code for java.util.concurrent.atomic.AtomicLong.getAndSet(long) definition code for java.util.concurrent.atomic.AtomicLong.getAndSet(long)

public final long getAndSet(long newValue)
Set to the give value and return the old value.

Parameters:
newValue - the new value
Returns:
the previous value

compareAndSet sample code for java.util.concurrent.atomic.AtomicLong.compareAndSet(long, long) definition code for java.util.concurrent.atomic.AtomicLong.compareAndSet(long, long)

public final boolean compareAndSet(long expect,
                                   long update)
Atomically set the value to the given updated value if the current value == the expected value.

Parameters:
expect - the expected value
update - the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicLong.weakCompareAndSet(long, long) definition code for java.util.concurrent.atomic.AtomicLong.weakCompareAndSet(long, long)

public final boolean weakCompareAndSet(long expect,
                                       long update)
Atomically set the value to the given updated value if the current value == the expected value. May fail spuriously.

Parameters:
expect - the expected value
update - the new value
Returns:
true if successful.

getAndIncrement sample code for java.util.concurrent.atomic.AtomicLong.getAndIncrement() definition code for java.util.concurrent.atomic.AtomicLong.getAndIncrement()

public final long getAndIncrement()
Atomically increment by one the current value.

Returns:
the previous value

getAndDecrement sample code for java.util.concurrent.atomic.AtomicLong.getAndDecrement() definition code for java.util.concurrent.atomic.AtomicLong.getAndDecrement()

public final long getAndDecrement()
Atomically decrement by one the current value.

Returns:
the previous value

getAndAdd sample code for java.util.concurrent.atomic.AtomicLong.getAndAdd(long) definition code for java.util.concurrent.atomic.AtomicLong.getAndAdd(long)

public final long getAndAdd(long delta)
Atomically add the given value to current value.

Parameters:
delta - the value to add
Returns:
the previous value

incrementAndGet sample code for java.util.concurrent.atomic.AtomicLong.incrementAndGet() definition code for java.util.concurrent.atomic.AtomicLong.incrementAndGet()

public final long incrementAndGet()
Atomically increment by one the current value.

Returns:
the updated value

decrementAndGet sample code for java.util.concurrent.atomic.AtomicLong.decrementAndGet() definition code for java.util.concurrent.atomic.AtomicLong.decrementAndGet()

public final long decrementAndGet()
Atomically decrement by one the current value.

Returns:
the updated value

addAndGet sample code for java.util.concurrent.atomic.AtomicLong.addAndGet(long) definition code for java.util.concurrent.atomic.AtomicLong.addAndGet(long)

public final long addAndGet(long delta)
Atomically add the given value to current value.

Parameters:
delta - the value to add
Returns:
the updated value

toString sample code for java.util.concurrent.atomic.AtomicLong.toString() definition code for java.util.concurrent.atomic.AtomicLong.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns the String representation of the current value.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the String representation of the current value.

intValue sample code for java.util.concurrent.atomic.AtomicLong.intValue() definition code for java.util.concurrent.atomic.AtomicLong.intValue()

public int intValue()
Description copied from class: Number sample code for java.lang.Number.intValue() definition code for java.lang.Number.intValue()
Returns the value of the specified number as an int. This may involve rounding or truncation.

Specified by:
intValue sample code for java.lang.Number.intValue() definition code for java.lang.Number.intValue() in class Number sample code for java.lang.Number definition code for java.lang.Number
Returns:
the numeric value represented by this object after conversion to type int.

longValue sample code for java.util.concurrent.atomic.AtomicLong.longValue() definition code for java.util.concurrent.atomic.AtomicLong.longValue()

public long longValue()
Description copied from class: Number sample code for java.lang.Number.longValue() definition code for java.lang.Number.longValue()
Returns the value of the specified number as a long. This may involve rounding or truncation.

Specified by:
longValue sample code for java.lang.Number.longValue() definition code for java.lang.Number.longValue() in class Number sample code for java.lang.Number definition code for java.lang.Number
Returns:
the numeric value represented by this object after conversion to type long.

floatValue sample code for java.util.concurrent.atomic.AtomicLong.floatValue() definition code for java.util.concurrent.atomic.AtomicLong.floatValue()

public float floatValue()
Description copied from class: Number sample code for java.lang.Number.floatValue() definition code for java.lang.Number.floatValue()
Returns the value of the specified number as a float. This may involve rounding.

Specified by:
floatValue sample code for java.lang.Number.floatValue() definition code for java.lang.Number.floatValue() in class Number sample code for java.lang.Number definition code for java.lang.Number
Returns:
the numeric value represented by this object after conversion to type float.

doubleValue sample code for java.util.concurrent.atomic.AtomicLong.doubleValue() definition code for java.util.concurrent.atomic.AtomicLong.doubleValue()

public double doubleValue()
Description copied from class: Number sample code for java.lang.Number.doubleValue() definition code for java.lang.Number.doubleValue()
Returns the value of the specified number as a double. This may involve rounding.

Specified by:
doubleValue sample code for java.lang.Number.doubleValue() definition code for java.lang.Number.doubleValue() in class Number sample code for java.lang.Number definition code for java.lang.Number
Returns:
the numeric value represented by this object after conversion to type double.