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 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 processes monitoring an MSMQ queue. I want to do multi-step operations
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 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
I have multiple JavaScript draggable DIV windows. When clicking a DIV, I want the
I have multiple files which I want to concat with cat . Let's say
I have multiple multi-select boxes with the same class and i want to unselect
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select

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.