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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:57:58+00:00 2026-05-11T08:57:58+00:00

There’s a name for this, but I don’t know what it is so it’s

  • 0

There’s a name for this, but I don’t know what it is so it’s hard to google.

What I’m looking for is something in the java concurrency utilities, which is a pair of queues, an "pending" queue used by a producer, and a "processing" queue used by a consumer, where the consumer can swap the queues atomically. If used in this way (1 producer thread, 1 consumer thread), the individual queues don’t need to be threadsafe, just the references to them.

I know I’ve seen this somewhere before, and I can probably cobble together something like this on my own, but if it exists already I’d rather use that.

edit: I guess the primitive I’m looking for is a pair of atomic references that can be atomically swapped. (& I can add the queues myself.)


edit 2: @Alex Miller answered the nagging question of what it was that I was thinking of but couldn’t remember. However that doesn’t solve my problem since it’s a thread barrier and I want the producer to not have to block.

@sfossin’s point about swapping references to queues is a good one; what I wanted was that the instant the consumer starts retrieving and processing items from the queue, all those queue items have to be complete and the producer can’t add any items afterwards; the producer now has to add items to the other queue. So the paired/swapped set of atomic references won’t work.

(It’s sort of like if there are 2 school buses, one of which is always waiting for passengers and the other is always delivering them elsewhere. Once the driver pulls away, that’s it, you have to get on the other bus. Having references lets producers access the bus even though it’s already left, which is not allowed.)

I think what I will do instead is to use a single ConcurrentLinkedQueue and have a sentinel value that the consumer adds to the queue. This allows there to be multiple producers, not just 1. In order for the consumer to process batches of items on the queue, the consumer waits for there to be at least 1 item on the queue, then inserts the sentinel at the end of the queue, and removes items until the sentinel is removed. Then the consumer does whatever it has to do between batches. That’s the behavior I wanted.

It doesn’t necessarily need to be a guaranteed non-blocking approach (locking or synchronized methods are options), but if there’s an easy way to architect it so that it is, that’s preferred in my application.

  • 1 1 Answer
  • 3 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. 2026-05-11T08:57:59+00:00Added an answer on May 11, 2026 at 8:57 am

    Exchanger?

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

Sidebar

Related Questions

There is previous little on the google on this subject other than people asking
There are numerous Agile software development methods. Which ones have you used in practice
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There seem to be many ways to define singletons in Python. Is there a
There are a few ways to get class-like behavior in javascript, the most common
There are several types of objects in a system, and each has it's own
There is a field in my company's Contacts table. In that table, there is
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql

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.