AtomicBoolean.compareAndSet(boolean expect, boolean update) has the following syntax.
public final boolean compareAndSet(boolean expect, boolean update)
In the following code shows how to use AtomicBoolean.compareAndSet(boolean expect, boolean update) method.
import java.util.concurrent.atomic.AtomicBoolean; /* ww w.j ava 2 s . c om*/ public class Main { public static void main(String[] argv) throws Exception { AtomicBoolean atomicBoolean = new AtomicBoolean(); atomicBoolean.compareAndSet(true,true); System.out.println(atomicBoolean); } }
The code above generates the following result.