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 to do it...

Follow these steps to implement the example:

  1. Copy the MyThread, MyThreadFactory, and MyTask classes into the project. They were implemented in the Implementing the ThreadFactory interface to generate custom threads for the fork/join framework recipe. You are going to use them in this example.
  2. Implement the main class of the example by creating a class named Main with a main() method:
        public class Main {           public static void main(String[] args) throws Exception {
  1. Create a new MyThreadFactory object named threadFactory:
        MyThreadFactory threadFactory=new MyThreadFactory                                                  ("MyThreadFactory");
  1. Create a new Executor object using the newCachedThreadPool() method of the Executors class. Pass the factory object created earlier ...

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