How to do it...

Follow these steps to implement the example:

  1. Create a class named ExecutableTask and specify that it implements the Callable interface parameterized by the String class:
        public class ExecutableTask implements Callable<String> {
  1. Declare a private String attribute called name. It will store the name of the task. Implement the getName() method to return the value of this attribute:
        private final String name;         public String getName(){           return name;         }
  1. Implement the constructor of the class to initialize the name of the task:
        public ExecutableTask(String name){           this.name=name;         }
  1. Implement the call() method. Put the task to sleep for a random period of time and return a message with the name of the task:
 @Override ...

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.