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

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