AtomicInteger.weakCompareAndSet(int expect, int update) has the following syntax.
public final boolean weakCompareAndSet(int expect, int update)
In the following code shows how to use AtomicInteger.weakCompareAndSet(int expect, int update) method.
//from ww w. ja va2 s .c o 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.