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

  • Home
  • SEARCH
  • 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 9158427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:14:37+00:00 2026-06-17T13:14:37+00:00

I am looking for a load balanced thread pool with no success so far.

  • 0

I am looking for a load balanced thread pool with no success so far. (Not sure whether load balancing is the correct wording).
Let me explain what I try to achieve.

Part 1:
I have Jobs, with 8 to 10 single tasks. On a 6 core CPU I let 8 thread work on this tasks in parallel which seems to deliver best peformance. Whe one task is ready, another one can start. Once all ten tasks are finished, the complete job is done. Usually a job is done in 30 to 60 seconds.

Part two:
Some times, unfortunately, the job takes more then two hours. This is correct due to amount of data that has to be calculated.
The bad thing is, that no other job can start while job1 is running (assuming, that all threads have the same duration) because it is using all threads.

My First idea:
Have 12 threads, allow up to three jobs in parallel.
BUT: that means, the cou is not fully untilized when there is only 1 job.

I am looking for a solution to have full CPU power for job one when there is no other job. But when an other job needs to be started while one other is running, I want the CPU power allocated to both job. And when a third or fourth job shows up, I want the cpu power alocated fairly to all four jobs.

I apreciate your answers…

thanks in advance

  • 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-17T13:14:38+00:00Added an answer on June 17, 2026 at 1:14 pm

    One possibility might be to use a standard ThreadPoolExecutor with a different kind of task queue

    public class TaskRunner {
      private static class PriorityRunnable implements Runnable,
                Comparable<PriorityRunnable> {
        private Runnable theRunnable;
        private int priority = 0;
        public PriorityRunnable(Runnable r, int priority) {
          this.theRunnable = r;
          this.priority = priority;
        }
    
        public int getPriority() {
          return priority;
        }
    
        public void run() {
          theRunnable.run();
        }
    
        public int compareTo(PriorityRunnable that) {
          return this.priority - that.priority;
        }
      }
    
      private BlockingQueue<Runnable> taskQueue = new PriorityBlockingQueue<Runnable>();
    
      private ThreadPoolExecutor exec = new ThreadPoolExecutor(8, 8, 0L,
                TimeUnit.MILLISECONDS, taskQueue);
    
      public void runTasks(Runnable... tasks) {
        int priority = 0;
        Runnable nextTask = taskQueue.peek();
        if(nextTask instanceof PriorityRunnable) {
          priority = ((PriorityRunnable)nextTask).getPriority() + 1;
        }
        for(Runnable t : tasks) {
          exec.execute(new PriorityRunnable(t, priority));
          priority += 100;
        }
      }
    }
    

    The idea here is that when you have a new job you call

    taskRunner.runTasks(jobTask1, jobTask2, jobTask3);
    

    and it will queue up the tasks in such a way that they interleave nicely with any existing tasks in the queue (if any). Suppose you have one job queued, whose tasks have priority numbers j1t1=3, j1t2=103, and j1t3=203. In the absence of other jobs, these tasks will execute one after the other as quickly as possible. But if you submit another job with three tasks of its own, these will be assigned priority numbers j2t1=4, j2t2=104 and j2t3=204, meaning the queue now looks like

    j1t1, j2t1, j1t2, j2t2, etc.

    This is not perfect however, because if all threads are currently working (on tasks from job 1) then the first task of job 2 can’t start until one of the job 1 tasks is complete (unless there’s some external way for you to detect this and interrupt and re-queue some of job 1’s tasks). The easiest way to make things more fair would be to break down the longer-running tasks into smaller segments and queue those as separate tasks – you need to get to a point where each individual job involves more tasks than there are threads in the pool, so that some of the tasks will always start off in the queue rather than being assigned directly to threads (if there are idle threads then exec.execute() passes the task straight to a thread without going through the queue at all).

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

Sidebar

Related Questions

We're looking to implement load balancing by horizontally sharding our tables across a cluster
I am looking for a solution that allows me to deploy multiple load balanced
I was looking at best load balancing option for concurrent users with Mongo DB.
I'm looking to implement Round Robin Load Balancing in Java on a very simple
I am looking to load results from the server for UITableView while I have
I'm looking to use jQuery's .load() or .get() functions to replace AJAX, I've got
I'm looking for a way to load an XML file's contents directly into a
I'm looking for a way to load invalid (malformed) XML into an AS3 XML
I'm looking for a way to load a page (page A) (which I also
I am looking for an opensource/free load testing tool to test applications over RMI.

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.