How to do it...

Follow these steps to implement the example:

  1. Create a class named MyThread that extends the Thread class:
        public class MyThread extends Thread {
  1. Declare three private Date attributes named creationDate, startDate, and finishDate:
        private final Date creationDate;         private Date startDate;         private Date finishDate;
  1. Implement a constructor of the class. It receives the name and the Runnable object to be executed as parameters. Initialize the creation date of the thread:
        public MyThread(Runnable target, String name ){           super(target,name);           creationDate = new Date();         }
  1. Implement the run() method. Store the start date of the thread, call the run() method of the parent class, and store the finish date of the execution: ...

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.