Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8277377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:40:31+00:00 2026-06-08T08:40:31+00:00

I have an application that processes data stored in a number of files from

  • 0

I have an application that processes data stored in a number of files from an input directory and then produces some output depending on that data.

So far, the application works in a sequential basis, i.e. it launches a “manager” thread that

  • Reads the contents of the input directory into a File[] array
  • Processes each file in sequence and stores results
  • Terminates when all files are processed

I would like to convert this into a multithreaded application, in which the “manager” thread

  • Reads the contents of the input directory into a File[] array
  • Launches a number of “processor” threads, each of which processes a single file, stores results and returns a summary report for that file to the “manager” thread
  • Terminates when all files have been processed

The number of “processor” threads would be at most equal to the number of files, since they would be recycled via a ThreadPoolExecutor.

Any solution avoiding the use of join() or wait()/notify() would be preferrable.

Based on the above scenario:

  1. What would be the best way of having those “processor” threads reporting back to the “manager” thread? Would an implementation based on Callable and Future make sense here?
  2. How can the “manager” thread know when all “processor” threads are done, i.e. when all files have been processed?
  3. Is there a way of “timing” a processor thread and terminating it if it takes “too long” (i.e., it hasn’t returned a result despite the lapse of a pre-configured amount of time)?

Any pointers to, or examples of, (pseudo-)source code would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:40:33+00:00Added an answer on June 8, 2026 at 8:40 am

    You can definitely do this without using join() or wait()/notify() yourself.

    You should take a look at java.util.concurrent.ExecutorCompletionService to start with.

    The way I see it you should write the following classes:

    • FileSummary – Simple value object that holds the result of processing a single file
    • FileProcessor implements Callable<FileSummary> – The strategy for converting a file into a FileSummary result
    • File Manager – The high level manager that creates FileProcessor instances, submits them to a work queue and then aggregates the results.

    The FileManager would then look something like this:

    class FileManager {
       private CompletionService<FileSummary> cs; // Initialize this in constructor
    
       public FinalResult processDir(File dir) {
          int fileCount = 0;
          for(File f : dir.listFiles()) {
             cs.submit(new FileProcessor(f));
             fileCount++;
          }
    
          for(int i = 0; i < fileCount; i++) {
             FileSummary summary = cs.take().get();
             // aggregate summary into final result;
          }
       }
    

    If you want to implement a timeout you can use the poll() method on CompletionService instead of take().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that processes files in a directory and moves them to
Assume I have a application that stores data,gets data and processes data and stores
I have an application that records data from a manufacturing process on a periodic
I have console application. In that i have some process that fetch the data
All, I have a huge application that processes media files. I get 102% CPU
Scenario I have a C# windows forms application that has a number of processes.
For instance, you have an application which processes files that are sent by different
I have an application that consists of two processes (let's call them A and
I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
I have a multi-process python application (processes are spawned by uwsgi) that needs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.