How it works...

The program starts creating a Phaser object that will control the synchronization of the threads at the end of each phase. The constructor of Phaser receives the number of participants as a parameter. In our case, Phaser has three participants. This number indicates Phaser the number of threads that need to execute the arriveAndAwaitAdvance() method before Phaser could change the phase and wake up the threads that have been sleeping.

Once Phaser has been created, we launch three threads that are executed using three different FileSearch objects.

In this example, we use paths of the Windows operating system. If you work with another operating system, modify the paths to adapt them to existing paths in your environment, such ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.