[当使用AtomicInteger时,我发现此API提供了两种方法。
compareAndExchange:
以原子方式将值设置为newValue以作证人值== ExpectedValue,记忆效应为由
VarHandle.compareAndExchange(java.lang.Object...)
指定
compareAndSet:
如果当前的
newValue
以原子方式将值设置为value == expectedValue
,则具有由VarHandle.compareAndSet(java.lang.Object...)
。
我无法理解两者之间的区别,请提供适当的示例以帮助。