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 to do it...

Follow these steps to implement the example:

  1. Create a class named Task that implements the Callable interface parameterized by the String class:
        public class Task implements Callable<String> {
  1. Declare a private String attribute called name that will store the name of the task:
        private final String name;
  1. Implement the constructor of the class that initializes the name attribute:
        public Task(String name) {           this.name=name;         }
  1. Implement the call() method. Write a message to the console with the actual date and return some text, for example, Hello, world:
        public String call() throws Exception {           System.out.printf("%s: Starting at : %s\n",name,new Date());           return "Hello, world";         }
  1. Implement the main class 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