O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

As mentioned in the introduction, there are other atomic classes in Java. AtomicBoolean, AtomicInteger, and AtomicReference are other examples of atomic classes.

The LongAdder class provides other interesting methods as follows:

  • add(): To increment the value of the internal counter by the value specified as a parameter
  • decrement(): To decrement the internal counter by one
  • reset(): To return the internal value to zero

You can also use the DoubleAdder class that is similar to LongAdder, but it doesn't have the increment() and decrement() methods and the internal counter is a double value.

You can also use the LongAccumulator class that is similar to DoubleAccumulator but with an internal long counter.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required