• Post Reply Bookmark Topic Watch Topic
  • New Topic

random behavior of flush()

 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i use flush method in my programs i get random behavior from the program. I have set the atuoflush of PrintWriter to true. But still some times my program stalls at (while(!bufferedreader.ready)) and when i explicitly flush the stream at the other end the program moves forward.
Can anyone tell me what am I doing wrong. What is the cause of this random behaviour.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PrintWriter will only flush when you can one of its println() methods. No other PrintWriter methods will do this, so it's possible to send data that needs to be flushed manually. Also note that printing a newline (\n) is not the same as calling println().
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ... so can i manually flush every time i use println instead of using the autoflush. and what happens when i call the flush method when there is nothing to flush in the stream
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call flush as often as you like; nothing bad will happen. If there's no buffered data, then it just doesn't do anything.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!