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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:10:59+00:00 2026-05-31T10:10:59+00:00

I have multiple BlockingQueues containing messages to be sent. Is it possible to have

  • 0

I have multiple BlockingQueues containing messages to be sent. Is it possible to have fewer consumers than queues? I don’t want to loop over the queues and keep polling them (busy waiting) and I don’t want a thread for every queue. Instead, I would like to have one thread that is awoken when a message is available on any of the queues.

  • 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-05-31T10:11:00+00:00Added an answer on May 31, 2026 at 10:11 am

    One trick that you could do is to have a queue of queues. So what you’d do is have a single blocking queue which all threads subscribe to. Then when you enqueue something into one of your BlockingQueues, you also enqueue your blocking queue on this single queue. So you would have something like:

    BlockingQueue<WorkItem> producers[] = new BlockingQueue<WorkItem>[NUM_PRODUCERS];
    BlockingQueue<BlockingQueue<WorkItem>> producerProducer = new BlockingQueue<BlockingQueue<WorkItem>>();
    

    Then when you get a new work item:

    void addWorkItem(int queueIndex, WorkItem workItem) {
        assert queueIndex >= 0 && queueIndex < NUM_PRODUCERS : "Pick a valid number";
        //Note: You may want to make the two operations a single atomic operation
        producers[queueIndex].add(workItem);
        producerProducer.add(producers[queueIndex]);
    }
    

    Now your consumers can all block on the producerProducer. I am not sure how valuable this strategy would be, but it does accomplish what you want.

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

Sidebar

Related Questions

I have multiple (8) WAR files and 1 EAR file that I want to
I have multiple DIVs containing an image in each. When I rollover these DIVs,
I have multiple threads processing events. I want to assign a nanosecond timestamp to
I have multiple variables containing JSON as string (received from AJAX). data.output_data_1234 data.output_data_5678 I
I have multiple activities in which I want to use same code in those
I have multiple div elements with same id='mydiv'.I want to calculate these divs and
I have multiple models that I want to search such that the results can
I have multiple publishers which want to persist their subscription info in storage. Is
I have multiple ImageViews in a UIScrollView and I want to identify the specific
I have multiple domains with multiple copies of jQuery.js in separate subfolders. I want

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.