Java AtomicBoolean .getAndSet (boolean newValue)

Syntax

AtomicBoolean.getAndSet(boolean newValue) has the following syntax.

public final boolean getAndSet(boolean newValue)

Example

In the following code shows how to use AtomicBoolean.getAndSet(boolean newValue) method.


//from ww  w  . jav  a 2s  .co  m
import java.util.concurrent.atomic.AtomicBoolean;

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

The code above generates the following result.





















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




AtomicBoolean
AtomicInteger
AtomicIntegerArray
AtomicLong
AtomicLongArray