1.AtomicInteger的基本方法
(1) 创建一个不传值的,此时默认值为0
AtomicInteger atomicInteger = new AtomicInteger(); System.out.println(atomicInteger.get()); ---->输出: 0
(2) set()/get()
AtomicInteger atomicInteger = new AtomicInteger(); atomicInteger.set(999); System.out.println(atomicInteger.get()); ---->输出: 999
(3) getAndAdd()方法与AddAndGet方法
AtomicInteger atomicInteger = new AtomicInteger(123); System.out.println(atomicInteger.getAndAdd(10)); --123 AtomicInteger atomicInteger = new AtomicInteger(123); System.out.println(atomicInteger.addAndGet(10)); --133
(4) getAndDecrement()和DecrementAndGet()方法
AtomicInteger atomicInteger = new AtomicInteger(123); System.out.println(atomicInteger.get()); --123 System.out.println(atomicInteger.getAndDecrement()); --123 获取当前值并自减 System.out.println(atomicInteger.get()); --122 System.out.println(atomicInteger.decrementAndGet()); --121 先自减再获取减1后的值 System.out.println(atomicInteger.get()); --121