How it works...

In the How it works... section of the previous recipe, you have a detailed explanation of how the MyThread, MyThreadFactory, and MyTask classes work.

In the main() method of the example, you created an Executor object using the newCachedThreadPool() method of the Executors class. You passed the factory object created earlier as a parameter, so the Executor object created will use that factory to create the threads it needs and also execute threads of the MyThread class.

Execute the program and you will see a message with information about the thread's start date and its execution time. The following screenshot shows the output generated by this example:

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.