Java AtomicInteger.set(int newValue)

Syntax

AtomicInteger.set(int newValue) has the following syntax.

public final void set(int newValue)

Example

In the following code shows how to use AtomicInteger.set(int newValue) method.


// w ww .  j  av a2s  .c o m
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicInteger atomicInteger = new AtomicInteger();
    
    atomicInteger.set(2);
    
    System.out.println(atomicInteger);
  }
}

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray