May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to {@code compareAndSet}. @param expect the expected value @param update the new value @return {@code true} if successful
4546474849505152535455
} @Test public void weakCompareAndSet() throws Exception { AtomicInteger value = new AtomicInteger(); assert value.weakCompareAndSet(0, 10); assert value.get() == 10; assert !value.weakCompareAndSet(20, 30); assert value.get() == 10; }
4849505152535455565758
public void weakCompareAndSet() throws Exception { AtomicInteger value = new AtomicInteger(); assert value.weakCompareAndSet(0, 10); assert value.get() == 10; assert !value.weakCompareAndSet(20, 30); assert value.get() == 10; } @Test public void lazySet() throws Exception {