Avoiding Busy-Wait When Opening a Thread's Input Stream

I am trying to avoid using busy wait when, after opening a child thread's input stream, I wait for it it to be ready before I start reading from it. A segment of the code follows:

BufferedReader reader=

new BufferedReader(new InputStreamReader(child.getInputStream()));

while (true){

while (!reader.ready()){}

input = reader.readLine();

// rest of code

}

Any ideas on how to get rid of the tight loop? I thought I wouldn't even need it there since reader is buffered. I thought the thread would just block if I tried to read before it was ready, but without that tight loop there, the code doesn't work.

[963 byte] By [Jus144ticea] at [2007-10-2 10:42:09]
# 1

The way I usually code buffered readers is:

String s = null;

BufferedReader br = ...;

while ((s = br.readLine()) != null) {

System.out.println(s); // example only

}

br.close();

rkippena at 2007-7-13 2:50:29 > top of Java-index,Other Topics,Algorithms...