Is thread sleep necessary when reading from a socket stream?
I am reading from a socket input stream like this
BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line;
while((line = in.readLine()) != null){
// do something
Thread.sleep(10); // for example 10ms
}
Now, the read method of an input stream blocks until data is available.
In this case is cooling-down the thread a good idea? After 10ms it will be
blocking anyway.
Please do not tell me about non-blocking IO, I know about that.
I am just curious whether it helps performance/CPU in anyway.
No comments:
Post a Comment