java-并发-源码-AtomicInteger

包含一个unsafe,value用于保存值

    private static final Unsafe unsafe = Unsafe.getUnsafe();
    private static final long valueOffset;
	private volatile int value;
lazySet
getAndSet
compareAndSet
weakCompareAndSet
getAndIncrement
getAndDecrement
getAndAdd
incrementAndGet
decrementAndGet
addAndGet
getAndUpdate
updateAndGet
getAndAccumulate
accumulateAndGet
intValue/longValue/floatValue/doubleValue

例子:accumulateAndGet

    AtomicInteger atomicInteger = new AtomicInteger(10);
    class Opa implements IntBinaryOperator {
        @Override
        public int applyAsInt(int left, int right) {
            return 0;
        }
    }
    atomicInteger.accumulateAndGet(10, new IntBinaryOperator() {
        @Override
        public int applyAsInt(int left, int right) {
            return left*right;
        }
    });
posted @ 2016-09-02 22:08  zhangshihai1232  阅读(249)  评论(0)    收藏  举报