December 2015
Intermediate to advanced
298 pages
5h 30m
English
One more concept at play here is of masters and slaves (also known as workers). The master spawns off a bunch of workers that are connected via a queue.
Then, a worker thread recurs in the directory. Once it finds a file with a .txt extension, it hands over the file to the egrep worker thread, as shown in the following figure. The egrep worker searches for the pattern in the file and prints out the matching lines:

Figure 10.3: Master/slave threads
The master thread recursively traverses the directory, looking for files with the .txt extension. Here is an example of the Java code. We've used the excellent Apache commons ...
Read now
Unlock full access