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