I have a thread that executes the following code:
public void run() {
try {
int n = 0;
byte[] buffer = new byte[4096];
while ((n
You could use the available() method (which is non-blocking) to check whether there is anything to read beforehand.
In pseudo-java:
//...
while(running)
{
if(in.available() > 0)
{
n = in.read(buffer);
//do stuff with the buffer
}
else
{
Thread.sleep(500);
}
}
//when running set to false exit gracefully here...