Java AtomicLong.addAndGet(long delta)

Syntax

AtomicLong.addAndGet(long delta) has the following syntax.

public final long addAndGet(long delta)

Example

In the following code shows how to use AtomicLong.addAndGet(long delta) method.


import java.util.concurrent.atomic.AtomicLong;
/*from w  w  w .  j  ava2 s  .  c o m*/
public class Main {
  public static void main(String[] argv) {
    AtomicLong nextId = new AtomicLong();

    System.out.println(nextId.getAndIncrement());
    System.out.println(nextId.addAndGet(100L));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.util.concurrent.atomic »




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray