I have a main program that runs a script on the target device (smartphone) and in a while loop waiting for a stdout message. However, in this particular case, some heartbeat messages on the standard output may be located at a distance of almost 45 seconds from a distance of up to 1 minute.
sort of:
stream = device.runProgram(RESTORE_LOGS, new String[] {}); stream.flush(); String line = stream.readLine(); while (line.compareTo("") != 0) { reporter.commentOnJob(jobId, line); line = stream.readLine(); }
So, I want to be able to start a new intermittent stream after reading a line from stdout with the required sleep window. Having the opportunity to read a new line, I want to be able to interrupt / stop (without having problems with killing the process), process a new line of stdout text and restart the process.
And this is an event in which I cannot read a line in the timer window (say 45 seconds), I want to exit my while loop.
I have already tried the thread.run method, thread.interrupt. But the problem is with killing and launching a new thread.
Is this the best way out, or am I missing something obvious?
source share