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 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.