Multithreading help using ExecutorService in Java : <p>I am trying to search a list of words and find the total count of all the words across multiple files.</p>

<p>My logic is to have separate threads for each file and get the count. Finally I can aggregate the total count got from each of the threads.</p>

<p>Say, I have 50 files each of 1MB. The performance does not improve when I am using multiple threads. My total execution time does not improve with <code>FILE_THREAD_COUNT</code>. I am getting almost the same execution time when my thread count is either 1 or 50.</p>

<p>Am I doing something wrong in using the executor service?</p>

<p>Here is my code. </p>

<pre><code>public void searchText(List&lt;File&gt; filesInPath, Set&lt;String&gt; searchWords) {
    try {
        BlockingQueue&lt;File&gt; filesBlockingQueue = new ArrayBlockingQueue&lt;&gt;(filesInPath.size());
        filesBlockingQueue.addAll(filesInPath);

        ExecutorService executorService = Executors.newFixedThreadPool(FILE_THREAD_COUNT);
        int totalWordCount = 0;
        while (!filesBlockingQueue.isEmpty()) {
            Callable&lt;Integer&gt; task = () -&gt; {
                int wordCount = 0;
                try {
                    File file = filesBlockingQueue.take();
                    try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
                        String currentLine;
                        while ((currentLine = bufferedReader.readLine()) != null) {
                            String[] words = currentLine.split("\\s+");
                            for (String word : words) {
                                for (String searchWord : searchWords) {
                                    if (word.contains(searchWord)) {
                                        wordCount++;
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        // Handle error
                    }
                } catch (Exception e) {
                    // Handle error
                }
                return wordCount;
            };
            totalWordCount += executorService.submit(task).get();
        }
        System.out.println("Final word count=" + totalWordCount);
        executorService.shutdown();
    } catch (Exception e) {
        // Handle error
    }
}
</code></pre>
