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 it works...

The key of this example is the Server class. This class creates and uses ThreadPoolExecutor to execute tasks.

The first important point is the creation of ThreadPoolExecutor in the constructor of the Server class. The ThreadPoolExecutor class has four different constructors, but due to their complexity, the Java concurrency API provides the Executors class to construct executors and other related objects. Although you can create ThreadPoolExecutor directly using one of its constructors, it's recommended that you use the Executors class.

In this case, you created a cached thread pool using the newFixedThreadPool() method of the Executors class in order to create the executor. This method creates an executor with the maximum ...

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