Follow these steps to implement the example:
- Create a class named MyExecutor that extends the ThreadPoolExecutor class:
public class MyExecutor extends ThreadPoolExecutor {
- Declare a private ConcurrentHashMap attribute parameterized by the String and Date classes, named startTimes:
private final ConcurrentHashMap<Runnable, Date> startTimes;
- 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<>(); ...