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 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<>(); ...

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