Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

available() method returning zero

 
Michael Monchu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am the first time on the forum and I am having a problem with retrieving the data from the InputStream. I have a Client program that sends the data to the ISeries Server and get a response and display it on a Web page. The problem is that when I run the program interactively, the available method returns zero, but when run in a debug mode, the available() returns the expected number of bytes. Can someone help me in explaining why the method would work only in a debug mode. Below is the source code used to read the data from the socket.



Please let me know if you need more information regarding this.

Thanks in advance.

Michael

 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this: AvailableDoesntDoWhatYouThinkItDoes.

Probably, in debug mode your code is running more slowly (especially if it's waiting for you to press buttons to step through something) and thus, whatever process is responsible for making bytes available has more time to achieve this. When you're not in debug mode, the code runs faster, and it goes through that code before bytes are actually available. Avoid using available(); it's fundamentally useless.
 
Michael Monchu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the code not to use the available(), and I'm glad to tell you that it's working perfectly.

Thanks a lot for your assistance.

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic