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 forms for lots of products on my page and want to
I have multiple domains on my server. I want to redirect all of them
I have multiple arrays with string values and I want to compare them and
I have multiple belongs_to relationships to the same model. Modeling messages between two users
I have multiple file open in Vim. When i want to switch from one
I have multiple pages containing the same partial view. The partial contains a form
I am trying to find out whether it is possible to have a multiple
I have multiple divs on my page.I want to copy selected text from div1
I have multiple ssl certificates for multiple pages. I want to run all pages
I have multiple jquery comboboxes on the same page and I want to 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.