Java AtomicBoolean .weakCompareAndSet (boolean expect, boolean update)

Syntax

AtomicBoolean.weakCompareAndSet(boolean expect, boolean update) has the following syntax.

public boolean weakCompareAndSet(boolean expect,   boolean update)

Example

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


/* w  w w  . j a  va2  s  .com*/
import java.util.concurrent.atomic.AtomicBoolean;

public class Main {
  public static void main(String[] argv) throws Exception {
    AtomicBoolean atomicBoolean = new AtomicBoolean();
    
    atomicBoolean.weakCompareAndSet(true,true);
    
    System.out.println(atomicBoolean);
  }
}

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray