Java API Tutorial - Java AtomicLong.getAndAdd(long delta)








Syntax

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

public final long getAndAdd(long delta)

Example

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

//  ww  w. j ava2s  .c om

import java.util.concurrent.atomic.AtomicLong;

public class Main {
  public static void main(String[] argv) {
    AtomicLong nextId = new AtomicLong();
    
    System.out.println(nextId.getAndAdd(12312L));
    
    System.out.println(nextId.getAndIncrement());
  }
}

The code above generates the following result.