AtomicLong.compareAndSet(long expect, long update) has the following syntax.
public final boolean compareAndSet(long expect, long update)
In the following code shows how to use AtomicLong.compareAndSet(long expect, long update) method.
/*from ww w . jav a 2 s . com*/ import java.util.concurrent.atomic.AtomicLong; public class Main { public static void main(String[] argv) { AtomicLong nextId = new AtomicLong(); nextId.compareAndSet(122L,123L); System.out.println(nextId.getAndIncrement()); } }
The code above generates the following result.