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

There's more...

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

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