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

Using our ThreadFactory in an Executor object

In the previous recipe, we introduced the factory pattern and provided an example of how to implement a factory of threads implementing the ThreadFactory interface.

The Executor framework is a mechanism that allows you to separate thread creation and its execution. It's based on the Executor and ExecutorService interfaces and the ThreadPoolExecutor class that implements both these interfaces. It has an internal pool of threads and provides methods that allow you to send two kinds of tasks to execute them in the pooled threads. These two kinds of tasks are as follows:

  • Classes that implement the Runnable interface, to implement tasks that don't return a result
  • Classes that implement the Callable ...

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