Wednesday, 28 August 2013

InputStream reader blocking thread

InputStream reader blocking thread

I wrote this InputStream reader to listen to a Socket. This code is in a
while(!stop) loop inside the run method of a thread. This reader blocks
the thread, and does not print the message.
int read = 0;
byte[] buf = new byte[512];
int index = 0;
try {
while (!stop && (read = in.read()) != -1) {
System.out.println("read loop");
buf[index++] = (byte) read;
}
} catch (IOException e) {
e.printStackTrace();
}

No comments:

Post a Comment