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

The Archive Base Latest Questions

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

I am getting data from a queue server and I need to process it

  • 0

I am getting data from a queue server and I need to process it and send an acknowledgement. Something like this:

while (true) {
    queueserver.get.data
    ThreadPoolExecutor //send data to thread
    queueserver.acknowledgement 

I don’t fully understand what happens in threads but I think this program gets the data, sends it the thread and then immediately acknowledges it. So even if I have a limit of each queue can only have 200 unacknowledged items, it will just pull as fast as it can receive it. This is good when I write a program on a single server, but if I’m using multiple workers then this becomes an issue because the amount of items in the thread queue are not a reflection of the work its done but instead of how fast it can get items from the queue server.

Is there anything I can do to somehow make the program wait if the thread queue is full of work?

  • 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-03T02:09:22+00:00Added an answer on June 3, 2026 at 2:09 am

    How can I make ThreadPoolExecutor command wait if there’s too much data it needs to work on?

    Instead of an open-ended queue, you can use a BlockingQueue with a limit on it:

    BlockingQueue<Date> queue = new ArrayBlockingQueue<Date>(200);
    

    In terms of jobs submitted to an ExecutorService, instead of using the default ExecutorServices created using Executors, which use an unbounded queue, you can create your own:

    return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS,
                  new ArrayBlockingQueue<Runnable>(200));
    

    Once the queue fills up, it will cause it to reject any new tasks that are submitted. You will need to set a RejectedExecutionHandler that submits to the queue. Something like:

    final BlockingQueue queue = new ArrayBlockingQueue<Runnable>(200);
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(nThreads, nThreads,
               0L, TimeUnit.MILLISECONDS, queue);
    // by default (unfortunately) the ThreadPoolExecutor will throw an exception
    // when you submit the 201st job, to have it block you do:
    threadPool.setRejectedExecutionHandler(new RejectedExecutionHandler() {
       public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
          // this will block if the queue is full
          executor.getQueue().put(r);
          // check afterwards and throw if pool shutdown
          if (executor.isShutdown()) {
             throw new RejectedExecutionException(
                  "Task " + r + " rejected from " + e);
          }
       }
    });
    

    I think it’s a major miss that Java doesn’t have a ThreadPoolExecutor.CallerBlocksPolicy.

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

Sidebar

Related Questions

Im getting data from a server by executing this code: - (void) sendGeneral:(NSString *)
how can i getting data from listbox in second form named listform while i
I am getting data from server it gives in response a NSString which hase
I have a custom list view that is getting data from server and changing
If I'm getting my data from Mysql like so: $result = $dbConnector->Query(SELECT * FROM
From debugger in my string of arrays I am getting this: "/mercedes-benz/190-class/1993/" class="canonicalLink" data-qstring="?sub=sedan">1993
I am getting data from iphone using php but when i insert post data
I have the following two methods for getting data from my database: - (void)
What are the differences between using SqlDataAdapter vs SqlDataReader for getting data from a
I have the following situation. Im getting data from an external system in the

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.