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

There's more...

You can test two interesting variants of this example:

  • If you comment the following line in the Handler class and execute the program, you will see a lot of messages written in the console. The ForkJoinPool class tries to start a worker thread to execute the task and, as it can't because they always throw an exception, it tries it over and over again:
        System.exit(-1); 
  • Something like that occurs if you change the third parameter (the exception handler) of the ForkJoinPool class constructor for the null value. In this case, you will see how the JVM writes the exceptions in the console.
  • Take this into account when you implement your own worker threads that could throw exceptions.

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