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 7976797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:00:23+00:00 2026-06-04T09:00:23+00:00

We have an application which processes a queue of documents (basically all the documents

  • 0

We have an application which processes a queue of documents (basically all the documents found in an input directory). The documents are read in one by one and are then processed. The application is an obvious candidate for threading since the results from processing one document are completely independent from the results of processing any other document. The question I have is how to divide the work.

One obvious way to split the work is to count the number of documents in the queue, divide by the number of available processors and split the work accordingly (example, the queue has 100 documents and I have 4 available processors, I create 4 threads and feed 25 documents from the queue to each thread).

However, a coworker suggests that I can just spawn a thread for each document in the queue and let the java JVM sort it out. I don’t understand how this could work. I do get that the second method results in cleaner code, but is it just as efficient (or even more efficient) than the first method?

Any thoughts would be appreciated.

Elliott

  • 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-04T09:00:24+00:00Added an answer on June 4, 2026 at 9:00 am

    We have an application which processes a queue of documents … how to divide the work?

    You should use the great ExecutorService classes. Something like the following would work. You would submit each of your files to the thread-pool and they will be processed by the 10 working threads.

     // create a pool with 10 threads
     ExecutorService threadPool = Executors.newFixedThreadPool(10);
     for (String file : files) {
         threadPool.submit(new MyFileProcessor(file));
     }
     // shutdown the pool once you've submitted your last job
     threadPool.shutdown();
     ...
     public class MyFileProcessor implements Runnable {
         private String file;
         public MyFileProcessor(String file) {
            this.file = file;
         }
         public run() {
            // process the file
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For instance, you have an application which processes files that are sent by different
We have a weblogic batch application which processes multiple requests from consumers at the
I have a distributed C++ application, which is composed of 4 processes spread on
I have a web application which basically process entries of the user when the
In our application we have a Queue which is defined as the following: private
I have an NServiceBus application for which a given message may not be processed
I have one spring batch application which can be run from command line. The
I have an application which runs some multi-threading process. In each thread I'm sharing
I have a C# application which launches another executable using Process.Start() . 99% of
I have a Silverlight application in which I catch certain key presses such as

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.