Java AtomicLong.getAndIncrement()

Syntax

AtomicLong.getAndIncrement() has the following syntax.

public final long getAndIncrement()

Example

In the following code shows how to use AtomicLong.getAndIncrement() method.


import java.util.concurrent.atomic.AtomicLong;
/* ww w . j a v  a2  s .co  m*/
public class Main {
  public static void main(String[] argv) {
    AtomicLong nextId = new AtomicLong();

    System.out.println(nextId.getAndIncrement());
  }
}

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray