How to do it...

Follow these steps to implement the example:

  1. Create a class named Result to store the results generated in the concurrent tasks of this example:
        public class Result {
  1. Declare two private attributes, namely a String attribute called name and an int attribute named value:
        private String name;         private int value;
  1. Implement the corresponding get() and set() methods to set and return the value of the name and value attributes:
        public String getName() {           return name;         }         public void setName(String name) {           this.name = name;         }         public int getValue() {           return value;         }         public void setValue(int value) {           this.value = value;         }
  1. Create a class named Task that implements the Callable interface parameterized by the Result ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.