Java AtomicInteger .weakCompareAndSet (int expect, int update)

Syntax

AtomicInteger.weakCompareAndSet(int expect, int update) has the following syntax.

public final boolean weakCompareAndSet(int expect,   int update)

Example

In the following code shows how to use AtomicInteger.weakCompareAndSet(int expect, int update) method.


// w ww  . j a va 2s  . co m
import java.util.concurrent.atomic.AtomicInteger;

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

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray