Java Code Examples for java.util.concurrent.atomic.AtomicLong.weakCompareAndSet()

The following are Jave code examples for showing how to use weakCompareAndSet() of the java.util.concurrent.atomic.AtomicLong class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File:   View Source Code Vote up 5 votes
 * repeated weakCompareAndSet succeeds in changing value when equal
 * to expected
public void testWeakCompareAndSet() {
    AtomicLong ai = new AtomicLong(1);
    do {} while (!ai.weakCompareAndSet(1, 2));
    do {} while (!ai.weakCompareAndSet(2, -4));
    assertEquals(-4, ai.get());
    do {} while (!ai.weakCompareAndSet(-4, 7));
    assertEquals(7, ai.get());