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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:54:39+00:00 2026-06-11T05:54:39+00:00

As in question. My current code is overkill for OS because it runs every

  • 0

As in question. My current code is overkill for OS because it runs every wget process in seperate thread, which is fine, but I have almost 15k files to download, so I want to use a thread pool for this job. Unfortunately I must use wget for download process.

    ExecutorService executor = Executors.newFixedThreadPool(5);
  for(String filename: files) {
        try {
            String encodedFilename = URLEncoder.encode(filename, "UTF-8");
            final String cmd = "wget --no-check-certificate -O " + filename +" " + BipDownloader.bipUrl + encodedFilename;

            Runnable run = new Runnable()
            {
                public void run() {
                    try {
                        System.out.println(cmd);
                        Process process = Runtime.getRuntime().exec(cmd);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }  

                }
            };
            executor.submit(run);
        } catch(IOException e) {
            System.err.println(e.getMessage());
        }    
  }

EDIT

Updated source code to use Thread Pool but my system still is unstable during download.

  • 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-11T05:54:40+00:00Added an answer on June 11, 2026 at 5:54 am

    Assuming that you do need to use wget, you can use an ExecutorService to handle a threadpool for you:

    ExecutorService executor = new FixedThreadPool(100); //pool of 100 threads
    
    ...
    
    Runnable r = new Runnable() {
    
        public void run() {
            try {
                System.out.println(cmd);
                Process process = Runtime.getRuntime().exec(cmd);
            } catch (IOException e) {
                e.printStackTrace();
            }  
        }
    }
    
    executor.submit(r);
    
    • The optimal size of the pool depends on various factors and it is best to test several numbers. Something between 100 and 1000 should be ok.
    • If you need to monitor the progress of the executions, you can store the futures returned by executor.submit, or you can use a CompletionExecutorService.

    EDIT

    As noted in the comments, exec is non blocking so in theory, it is possible that all processes will be started before any of them has finished, even if the size of the pool is limited. To prevent that you should wait until in your run method until the process finishes:

    Process process = Runtime.getRuntime().exec(cmd);
    int exitVal = process.waitFor();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a simple question but I only have Linux to test this code on
Yet another PHP date question for everyone - I have the current code for
This question is related to a previous question of mine That's my current code
This question is mainly to verify my current idea. I have a series of
Drupal Question: Does anyone have a method of using Views and highlighting a selected/current
I have a short question. Im my current project I'm using LINQ-to-SQl. That is
I have an application which needs to be able to write to Any User/Current
I'm newbie in Python, but this question is not a homework (actually this code
This question is based on the thread . I have the following Git-prompt at
A followup to this previous question: Current code: var query = from b in

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.