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

How it works...

In this example, you implemented two different tasks to work with an AtomicIntegerArray object:

  • Incrementer: This class increments all the elements of the array using the getAndIncrement() method
  • Decrementer: This class decrements all the elements of the array using the getAndDecrement() method

In the Main class, you created AtomicIntegerArray with 1,000 elements, then you executed 100 incrementer and 100 decrementer tasks. At the end of these tasks, if there were no inconsistency errors, all the elements of the array must have the value 0. If you execute the program, you will see how the program only writes the final message to the console because all the elements are zero.

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