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

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