I'm currently wondering how expensive is calling on a BufferedReader instance read() to know if there is data to read.
In my case the BufferReader is wrapping a socket connection.
I have a sleep of 100 ms at the moment, because I don't want to execute it constantly. But to be honest I'm not sure what would be a reasonable amount of time to wait or should I wait at all?
It blocks. You don't need to sleep at all.
'To know if there is data to be read' doesn't make sense. You can't use it for that. You don't need to use it for that. Just block.
If you're talking about available()
, or ready()
, the answer is much the same. You don't need it, and you don't need to sleep around it. Just block in read()
.