Java AtomicLong .weakCompareAndSet (long expect, long update)
Syntax
AtomicLong.weakCompareAndSet(long expect, long update) has the following syntax.
public final boolean weakCompareAndSet(long expect, long update)
Example
In the following code shows how to use AtomicLong.weakCompareAndSet(long expect, long update) method.
import java.util.concurrent.atomic.AtomicLong;
/* w w w .j a v a 2s.co 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.