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