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

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:

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