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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:27:55+00:00 2026-05-29T06:27:55+00:00

Consider the following snippet. qIn is a BlockingQueue , LinkedBlockingQueue implementation while (true) {

  • 0

Consider the following snippet. qIn is a BlockingQueue, LinkedBlockingQueue implementation

    while (true) {
        try {
            // retrieved = qIn.poll(999, TimeUnit.MILLISECONDS);  works
            retrieved = qIn.poll();                            // fails

            if (retrieved != null)
                consume(retrieved);

            if (!Producer.isAddingData && qIn.size() == 0)
                break;

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

Let me clarify what i mean by works and fails. When i say qIn.poll() fails, i refer to the fact that sometimes not all data in queue is processed.

Why it is the wait (qIn.poll(999, TimeUnit.MILLISECONDS) necessary

retrieved = qIn.poll(999, TimeUnit.MILLISECONDS); // works
retrieved = qIn.poll();                           // fails

When the following check is always being performed? Basically the check is “If your producer is no longer adding data and the queue to pull from contains no data, break“

if (!StopwordsFilter.isAddingData && qIn.size() == 0)
   break;

I wonder, under what circumstance qIn.poll(); fails?

Defined as follows, considering we break only when there is nothing to take, why would it break?

retrieves and removes the head of this queue, or returns null if this
queue is empty.

PS: I should add that qIn.poll() fails sometimes, not all the time

  • 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-29T06:27:56+00:00Added an answer on May 29, 2026 at 6:27 am

    poll() can return null because the information hasn’t been added to the queue quite yet, that’s why — but perhaps it might be added in a couple more milliseconds. poll() doesn’t do any waiting at all.

    If you want to wait…then you’re going to need to guess an upper bound on the time to wait. There’s no really good way of predicting this, but you can probably be generous — if I understand the situation correctly, you’re usually adding things to the queue quite quickly.

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

Sidebar

Related Questions

Please consider the following snippet from an implementation of the Interpreter pattern: public override
I have a question regarding exception handling. Consider following Java code snippet. try{ //code
Consider the following snippet: using System; using System.Collections.Generic; using System.Linq; using System.Net; namespace ForumLogins
Consider the following snippet of code: // get number of sheep in DataTable by
Consider the following snippet: $(document).bind('mousemove', function(e) { $('#someDiv').css({left: e.pageX+'px', top: e.pageY+'px'}); }); This should
Consider the following snippet: get '/hello/:name' do |n| Hello #{n}! end How can I
Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the following code snippet: $beat = date('B'); // 1 beat = 86.4 seconds,
Consider the following HTML snippet. The desired effect is to have a dropdown be
Consider the following snippet: int i = 99999999; byte b = 99; short s

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.