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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:03:44+00:00 2026-05-28T13:03:44+00:00

I have a bunch of producer threads adding to a BlockingQueue and one worker

  • 0

I have a bunch of producer threads adding to a BlockingQueue and one worker thread taking objects. Now I want to extend this so two worker threads are taking objects, but doing different work on the objects. Here’s the twist: I want an object that has been put on the queue to be worked on by both of the receiving threads.

If I keep using BlockingQueue, the two threads will compete for the objects, and only one of the worker threads will get the object.

So I’m looking for something similar to BlockingQueue, but with broadcast behaviour.

The application: The producer threads are actually creating performance measurements, and one of the workers is writing the measurements to a file, while the other worker is aggregating statistics.

I’m using Java 6.

So does such a mechanism exist? In Java SE? Elsewhere? Or do I need to code my own?

I’m looking for solutions with a small footprint – I’d prefer not to install some framework to do this.

  • 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-28T13:03:45+00:00Added an answer on May 28, 2026 at 1:03 pm

    One option: have three blocking queues. Your main producer puts items into a “broadcast” queue. You then have a consumer of that queue which consumes each item, putting it into both of the other queues, each of which is serviced by a single consumer:

                                       Q2
                                      ---- Real Consumer 1
              Q1                     /
    Producer ---- Broadcast Consumer
                                     \
                                      ---- Real Consumer 2
                                       Q3
    

    Alternatively, you could give two blocking queues to the producer, and just get it to put the items it produces into both. That’s less elegant, but slightly simpler overall 🙂

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

Sidebar

Related Questions

I have a bunch of classes I want to rename. Some of them have
I have a bunch of php arrays that look like this (please don't ask
I have a bunch of Yaml configuration files that I want to convert to
I have bug checked this code considerably now and made sure I am outputting
I have a bunch of threads that are doing lots of communication with each
I have a crash dump from my app showing a bunch of threads waiting
I have a bunch of Joda time Interval objects stored in a List. All
I have an NSMutableDictionary, analyzedPxDictionary , containing a bunch of Pixel objects (a custom
Note: This is .NET regular expressions. I have a bunch of text, from which
I have a list of files with a bunch of attributes. One of 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.