How to do it...

Follow these steps to implement the example:

  1. First, implement the tasks that will be executed by the server. Create a class named Task that implements the Runnable interface:
        public class Task implements Runnable {
  1. Declare a Date attribute named initDate to store the creation date of the task and a String attribute called name to store the name of the task:
        private final Date initDate;         private final String name;
  1. Implement the constructor of the class that initializes both the attributes:
        public Task(String name){           initDate=new Date();           this.name=name;         }
  1. Implement the run() method:
        @Override         public void run() {
  1. First, write the initDate attribute and the actual date, which is the starting date of the task: ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.