The Executors class provides other methods to create ThreadPoolExecutor:
- newCachedThreadPool(): This method returns an ExecutorService object, so it's been cast to ThreadPoolExecutor to have access to all its methods. The cached thread pool you created creates new threads, if needed, to execute new tasks. Plus, it reuses the existing ones if they have finished the execution of the tasks they were running.
- newSingleThreadExecutor(): This is an extreme case of a fixed-size thread executor. It creates an executor with only one thread so it can only execute one task at a time.
The ThreadPoolExecutor class provides a lot of methods to obtain information about its status. We used the getPoolSize(), getActiveCount(), and getCompletedTaskCount() ...