JAVA SE 8 学习笔记(五)并发增强

  • Post author:
  • Post category:java




1.原子值






java5开始,提供了一些原子操作的类,如AtomicInteger、AtomicLong等


这些类提供了诸如incrementAndGet这样的原子操作方法。


单数如果想进行复杂操作,则需要使用compareAndSet进行循环处理


do {




// .. 计算


} while (!atomicLong.compareAndSet(old, new));




在java8中提供了updateAndGet和accumulateAndGet方法



atomicLong,

updateAndGet

(x -> Max.max(x, observed));





版权声明:本文为flycct原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。