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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:23:16+00:00 2026-06-09T05:23:16+00:00

Currently I have a construct that does the following: An X number of threads

  • 0

Currently I have a construct that does the following:
An X number of threads (X being a configurable variable from the user) are all started and await for a task to become available. The threads block waiting in
a BlockingQueue.
Another thread(s) places task(s) in the blocking queue and the blocked threads take the task(s) and run them and go back to wait for the next task.
Anyway this works fine but I have the following issue. X threads are constantly waiting for a task even if there isn’t any for 2 hours.
Also X threads are actually available even if there are only lets’say X/50 tasks coming in (i.e. I have much more threads than I actually need).
So my question is, how could I refactor this (perhaps using Executors) so that X goes up and down as needed?
My aim is not to lose performance. I mean now I could have more threads than I would need (wasting resources) but I don’t have the overhead of creating new threads.
I am interested in refactoring this in a way to not waste resources and keep the same performance levels.

  • 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-09T05:23:19+00:00Added an answer on June 9, 2026 at 5:23 am

    Normal ThreadPoolExecutor should suffice. The basic constructor takes parameters for “core pool size” (minimum amount of threads to keep alive at all times), maximum size (maximum amount of threads) and the keep alive time of excess threads (idle threads above core pool size). Also, you can pass your BlockingQueue straight for the executor.

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

Sidebar

Related Questions

Currently have a drop down menu that is activated on a hover (from display:none
I currently have a function template, taking a reference, that does something in essence
A different question inspired the following thought: Does std::vector<T> have to move all the
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
I currently have a wcf service library project that includes my service contract &
I currently have an immutable type called Gene , that only has 2 fields:
I have a windows form application that uses a Shared class to house all
I'm trying to build a bookmarklet that does the following: 1.)loads an external js,

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.