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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:51:09+00:00 2026-06-03T12:51:09+00:00

I have a Java program that needs to call the same external executable 6

  • 0

I have a Java program that needs to call the same external executable 6 times. This executable produces an output file and once all 6 runs are complete I “merge” these files together. I did just have a for-loop where I ran the code, waited for the first run of the external executable to end then I called it again, etc.

I found this highly time consuming, averaging 52.4s for it to run 6 times… I figured it would be pretty easy to speed up by running the external executable 6 times all at once, especially since they aren’t dependent on one another. I used ExecutorService and Runnable, etc. to achieve this.

With my current implementation, I shave about ~5s off my time, making it only ~11% faster.

Here is some (simplified) code that explains what I’m doing:

private final List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();

....

private void setUpThreadsAndRun() {
    ExecutorService executor = Executors.newFixedThreadPool(6);

    for (int i = 0; i < 6; i++) {
        //create the params object
       tasks.add(Executors.callable(new RunThread(params)));
    }

    try {
        executor.invokeAll(tasks);
    } catch (InterruptedException ex) {
        //uh-oh
    }

    executor.shutdown();
    System.out.println("Finished all threads!");
}

private class RunThread implements Runnable {
    public RunThread(ModelParams params) {
        this.params = params;
    }

    @Override
    public void run()
    {
         //NOTE: cmdarray is constructed from the params object
        ProcessBuilder pb = new ProcessBuilder(cmdarray);
         pb.directory(new File(location));
         p = pb.start();
    }
}

I’m hoping there is a more efficient way to do this…or maybe I’m “clogging” my computer’s resources by trying to run this process 6 times at once. This process does involve file I/O and writes files that are about 30mb in size.

  • 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-03T12:51:12+00:00Added an answer on June 3, 2026 at 12:51 pm

    The only time that forking the executable 6 times will earn a performance boost is if you have at least 6 CPU cores and your application is CPU bound — i.e. mostly doing processor operations. Since each application writes a 30mb file, it sounds like it is doing a large amount of IO and the applications are IO bound instead — limited by your hardware’s ability to service the IO requests.

    To speed up your program, you might try 2 concurrent processes to see if you get an improvement. However, if you program is IO bound, then you will never get much of a speed improvement by forking multiple copies.

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

Sidebar

Related Questions

I have a Java program that is launched by a batch file with a
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a java program that generates an HTML file. The Java program takes
I Have a java program that does sort of this: It starts off with
I have a program that reads and draws an SVG file in a java
I have a java program that uses ProcessBuilder to call the unix sort command.
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes
I have a Java program that generates Java classes for my application. Basically it

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.