I'm experiencing some incredibly weird behavior in a java application.
Here is the loop in question
while(true)
{
System.out.println("feed message queue is... " + feedMessageQueue.peek());
//feedMessageQueue.peek();
if (this.feedMessageQueue.peek() != null ){
for (String message : feedMessageQueue)
{
System.out.println("Sending message to client: " + message);
out.println(message);
this.feedMessageQueue.remove();
}
}
}//end while
Now, I originally tried for my if condition if (feedMessageQueue.size() > 0) and that would not work.
However, this condition works (and the for loop is executed) ONLY WHEN I run the print statement above just under the while loop.
I thought perhaps it had to do with the peek() method, so I tried calling that instead of the print statement.
I'm really moreso just curious why I'd be seeing behavior like this? How could the print statement affect the following conditional?
Thanks for any thoughts!