Java API Tutorial - Java AtomicLong(long initialValue) Constructor








Syntax

AtomicLong(long initialValue) constructor from AtomicLong has the following syntax.

public AtomicLong(long initialValue)

Example

In the following code shows how to use AtomicLong.AtomicLong(long initialValue) constructor.

//from   w  w  w  . j  ava  2 s  .com
import java.util.concurrent.atomic.AtomicLong;

public class Main {
  public static void main(String[] argv) {
    AtomicLong nextId = new AtomicLong(123L);

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

The code above generates the following result.