I am new to Java and am using code given by someone. There, at the end of the code, they interrupt the stream if it is not already finished. I measure code time.
The problem is that Java code first issues all the threads and then interrupts at the end. Is interruption required? Can't we wait for all the threads to finish? Or it may just be to skip the interrupt (these threads are executed using the exec exec command and they will end anyway). Here is the relevant code. First, the code for a single thread:
String commandString = "./script.scr "; process = Runtime.getRuntime().exec(commandString); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); while ((lsString = bufferedReader.readLine()) != null) { System.out.println(lsString); } try { process.waitFor(); }
Now the code of the part that sends these streams:
public void stopWhenAllTaskFinished() { while(notFinished) {sleep(50);}
This function is called from the main class, for example:
obj.stopWhenAllTaskFinished()
I really appreciate any understanding or answer.
source share