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...

In this example we used the addToPendingCount() method to increment the counter of pending tasks, but we have other methods we can use to change the value of this counter:

  • setPendingCount(): This method establishes the value of the counter of pending tasks.
  • compareAndSetPendingCount(): This method receives two parameters. The first one is the expected value and the second one is the new value. If the value of the counter of pending tasks is equal to the expected value, establish its value to the new one.
  • decrementPendingCountUnlessZero(): This method decrements the value of the counter of pending tasks unless it's equal to zero.

The CountedCompleter class also includes other methods to manage the completion of the tasks. ...

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