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:

  • DocumentTask: A task of this class has to process a set of lines of the document determined by the start and end attributes. If this set of lines has a size smaller than 10, it creates LineTask per line, and when they finish their execution, it sums the results of those tasks and returns the result of the sum. If the set of lines the task has to process has a size of 10 or bigger, it divides the set in two and creates two DocumentTask objects to process those new sets. When those tasks finish their execution, the tasks sum their results and return that sum as a result.
  • LineTask: A task of this class has to process a set of words of a line of the document. If this set of ...

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