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

The following are Jave code examples for showing how to use weakCompareAndSet() of the java.util.concurrent.atomic.AtomicReference class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: openjdk-jdk10   File: AtomicReferenceTest.java   Source Code and License Vote up 5 votes
/**
 * repeated weakCompareAndSet succeeds in changing value when equal
 * to expected
 */
public void testWeakCompareAndSet() {
    AtomicReference ai = new AtomicReference(one);
    do {} while (!ai.weakCompareAndSet(one, two));
    do {} while (!ai.weakCompareAndSet(two, m4));
    assertSame(m4, ai.get());
    do {} while (!ai.weakCompareAndSet(m4, seven));
    assertSame(seven, ai.get());
}