Java AtomicIntegerArray .weakCompareAndSet (int i, int expect, int update)

Syntax

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

public final boolean weakCompareAndSet(int i,   int expect,   int update)

Example

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


import java.util.concurrent.atomic.AtomicIntegerArray;
//  w  w  w . j  av  a2 s  . c o  m
public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(new int[]{0,1,2,3});
    
    atomicIntegerArray.weakCompareAndSet(0,10,20);
    
    System.out.println(atomicIntegerArray);
  }
}

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray