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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:54:50+00:00 2026-05-21T03:54:50+00:00

I have a blocking priority queue which stores Objects of type Message, message has

  • 0

I have a blocking priority queue which stores Objects of type Message, message has String[] data = new String[10]. Now I have to iterate over whole blocking Queue, check if its Object message’s 2nd element is equal to 6th element of an incoming message.

The comparator of Messages is not based on 6th element which needs to be updated. Problem is that if I take out an object then how to put it at same position and if I use the code below to update it then anytime iter.next() is run it may start pointing to next Object.

Here is what I am trying.

public synchronized void updateAck(Message ackMessage)
    {
        Iterator iter  = localQ.iterator(); // localQ is the blocking priority queue here
        while(iter.hasNext())
        {
            if(((Message)iter.next()).data[2].equalsIgnoreCase(ackMessage.data[6]))
            {
                (Integer.parseInt((Message)iter.next()).data[6])+1);

            }
        }
    }
  • 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-21T03:54:51+00:00Added an answer on May 21, 2026 at 3:54 am

    Instead of directly using (Message)iter.next() in your if conditions, try this.

    Message queMessage = (Message)iter.next();
    

    Full code

     while(iter.hasNext())
    {
    
        Message queMessage = (Message)iter.next(); //you will be invoking .next() only once
    
         if(queMessage.data[2].equalsIgnoreCase(ackMessage.data[6]))
         {
              (Integer.parseInt(queMessage.data[6])+1);
    
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have made a prority blocking queue.Inserting is properly done based on priority.when i
I have a blocking queue of objects. I want to write a thread that
I have a blocking SSL BIO object which I want to send data to.
I have a app that has call blocking feature in it and that work
I have a bounded blocking queue in an application that was written several years
I have a webpage with ajax. Ajax HAS to load some data from other
I have partial C# code for a blocking queue that looks like this: private
I have a blocking queue and workers taking from that queue and then working
I have one thread that add() s objects into a LinkedList queue, and another
I have a non-blocking winsock socket that is recv 'ing data in a loop.

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.