(JAVA)Terminate function on System.in .. possible?
<p>I am currently working on a project in JAVA where I have to make an agent to interact with a server.</p>

<p>Each 50ms, the server will receive the last thing I outputted to System.out and send me a new set of lines as a 'state' through the System.in printstream to analyze and send my next message to System.out.</p>

<p>Also, if the server receives multiple outputs from me, it only regards the most recent one.</p>

<p>..</p>

<p>As for my question:</p>

<p>My program originally constructed a tree and then analyzed each leaf node to see which would be optimal, and then waited around for the next input, but I can recursively do a deeper tree search that would make my output 'better' (and again and again to keep returning a better result).</p>

<p>Using this and the fact that if the server receives multiple outputs, it only takes the most recent one, I could do each level, print my result and start the next level. But here comes my problem...</p>

<p>I can't be stuck in some complex algorithm while I am supposed to receiving the next input as I will then miss it. So I was wondering if there is a way to cancel anything else I am doing when I receive something via System.in and then go back to the beginning of the function and start the search again with the new set of input (and rinse and repeat..)</p>

<p>I hope this all makes sense,</p>

<p>Thank ye all</p>
