AtomicInteger
get()
: 获取当前值。int value = atomicInteger.get();
set(int newValue)
: 设置新值。atomicInteger.set(42);
incrementAndGet()
: 将当前值加一,并返回新值。int newValue = atomicInteger.incrementAndGet();
decrementAndGet()
: 将当前值减一,并返回新值。int newValue = atomicInteger.decrementAndGet();
addAndGet(int delta)
: 将当前值加上指定增量,并返回新值。int newValue = atomicInteger.addAndGet(10);
compareAndSet(int expect, int update)
: 如果当前值等于expect
,则将其更新为update
,并返回是否成功。boolean success = atomicInteger.compareAndSet(10, 20);
AtomicLong
get()
: 获取当前值。long value = atomicLong.get();
set(long newValue)
: 设置新值。atomicLong.set(100L);
incrementAndGet()
: 将当前值加一,并返回新值。long newValue = atomicLong.incrementAndGet();
decrementAndGet()
: 将当前值减一,并返回新值。long newValue = atomicLong.decrementAndGet();
addAndGet(long delta)
: 将当前值加上指定增量,并返回新值。long newValue = atomicLong.addAndGet(50L);
compareAndSet(long expect, long update)
: 如果当前值等于expect
,则将其更新为update
,并返回是否成功。boolean success = atomicLong.compareAndSet(100L, 200L);
AtomicBoolean
get()
: 获取当前布尔值。boolean value = atomicBoolean.get();
set(boolean newValue)
: 设置新布尔值。atomicBoolean.set(true);
compareAndSet(boolean expect, boolean update)
: 如果当前值等于expect
,则将其更新为update
,并返回是否成功。boolean success = atomicBoolean.compareAndSet(false, true);
AtomicReference<V>
get()
: 获取当前引用。V value = atomicReference.get();
set(V newValue)
: 设置新引用。atomicReference.set(newValue);
compareAndSet(V expect, V update)
: 如果当前引用等于expect
,则将其更新为update
,并返回是否成功。boolean success = atomicReference.compareAndSet(expectedValue, newValue);
getAndSet(V newValue)
: 设置新引用并返回旧引用。V oldValue = atomicReference.getAndSet(newValue);
AtomicMarkableReference<V>
getReference()
: 获取当前引用。V reference = markableReference.getReference();
isMarked()
: 获取标记。boolean marked = markableReference.isMarked();
set(V newReference, boolean newMark)
: 设置新引用和标记。markableReference.set(newReference, true);
compareAndSet(V expectedReference, V newReference, boolean expectedMark, boolean newMark)
: 如果当前引用和标记匹配expectedReference
和expectedMark
,则更新为newReference
和newMark
,并返回是否成功。boolean success = markableReference.compareAndSet(expectedReference, newReference, false, true);
AtomicStampedReference<V>
getReference()
: 获取当前引用。V reference = stampedReference.getReference();
getStamp()
: 获取当前戳。int stamp = stampedReference.getStamp();
set(V newReference, int newStamp)
: 设置新引用和戳。stampedReference.set(newReference, 1);
compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
: 如果当前引用和戳匹配expectedReference
和expectedStamp
,则更新为newReference
和newStamp
,并返回是否成功。boolean success = stampedReference.compareAndSet(expectedReference, newReference, 0, 1);
评论 (0)