How to do it...

Follow these steps to implement the example:

  1. Create a class called FileSearch and specify that it implements the Runnable interface:
        public class FileSearch implements Runnable {
  1. Declare two private attributes: one for the name of the file we are going to search for and one for the initial folder. Implement the constructor of the class, which initializes these attributes:
        private String initPath;         private String fileName;         public FileSearch(String initPath, String fileName) {           this.initPath = initPath;           this.fileName = fileName;         }
  1. Implement the run() method of the FileSearch class. It checks whether the attribute fileName is a directory; if it is, it calls the directoryProcess() method. This method can throw an ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.