Factory pattern is a widely used design pattern in the object-oriented programming world. It is a creational pattern and its objective is to develop a class whose mission is to create objects of one or several classes. Then, when we want to create an object of one of those classes, we use the factory instead of using the new operator.
Java provides the ThreadFactory interface to implement a Thread object factory. Some advanced utilities of the Java concurrency API, such as the Executor framework or the fork/join framework, use thread factories to create threads. Another example of the factory pattern in the Java Concurrency API is the Executors class. It provides a lot of methods to create different kinds of Executor objects. In this recipe, you will extend the Thread class by adding new functionalities, and you will implement a thread factory class to generate threads of this new class.