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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:40:45+00:00 2026-05-16T00:40:45+00:00

I have 3 threads: 2 consumers, ConsumerA and ConsumerB , and a Producer .

  • 0

I have 3 threads: 2 consumers, ConsumerA and ConsumerB, and a Producer.

I also have a LinkedBlockingQueue queue

At t=1: ConsumerA calls queue.take()

At t=2: ConsumerB calls queue.take()

At t=3: Producer calls queue.put(foo)

Is it guaranteed that ConsumerA receives foo before ConsumerB? In other words, the order in which the consumers invokes take() is the order in which each is notified?

If not, is there an alternative data structure that will give higher priority based on order?

  • 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-16T00:40:46+00:00Added an answer on May 16, 2026 at 12:40 am

    From looking at the source code, it’s not guaranteed. There’s a guarded block mechanism in place with the waking up of one thread at random, depending on how the scheduler feels.

     notEmpty.signal(); // propagate to a non-interrupted thread
    

    Full code: http://kickjava.com/src/java/util/concurrent/LinkedBlockingQueue.java.htm

    Edit: just looked again at ReenterantLock and Condition, the threads are signalled in FIFO order, apparently. So, the first thread to wait for insertion will be signalled first. However, these are implementation details! Do not rely on them.

    an implementation is not required to
    define exactly the same guarantees or
    semantics for all three forms of
    waiting, nor is it required to support
    interruption of the actual suspension
    of the thread

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

Sidebar

Related Questions

I have two threads, a producer thread that places objects into a generic List
I have a queue, a list with producer threads and a list with consumer
I have a Windows service that uses the producer/consumer queue model with multiple worker
I have multiple threads (C# application running on IIS) running that all need to
I have 2 threads and global Queue, one thread (t1) push the data and
I have multiple threads that share use of a semaphore. Thread A holds the
I have multiple threads each one with its own private concurrent queue and all
I have an object Producer which internally starts a thread that will listen for
I have two threads that use an event for synchronization. In each thread they
In a classic consumer\producer threads senario and i have to use a vector for

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.