How to do it...

Follow these steps to implement the example:

  1. Create a class named MyExecutor that extends the ThreadPoolExecutor class:
        public class MyExecutor extends ThreadPoolExecutor {
  1. Declare a private ConcurrentHashMap attribute parameterized by the String and Date classes, named startTimes:
        private final ConcurrentHashMap<Runnable, Date> startTimes;
  1. Implement the constructor for the class. Call a constructor of the parent class using the super keyword and initialize the startTime attribute:
        public MyExecutor(int corePoolSize, int maximumPoolSize,                          long keepAliveTime, TimeUnit unit,                          BlockingQueue<Runnable> workQueue) {          super(corePoolSize, maximumPoolSize, keepAliveTime, unit,                workQueue); startTimes=new ConcurrentHashMap<>(); ...

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.