Home > Back-end >  The parent can't quit
The parent can't quit

Time:09-17

I was in the spring the boot time task to invoke a Python program:
 Process P1=Runtime. The exec (... ) 


Then after I kill off the python program on the server, Java program has been no response, seems to have no exit, what reason be?

CodePudding user response:

Best to stick the main logic code, you couldn't see the specific question,
Most likely is the JAVA code has not closed process,

CodePudding user response:

reference 1st floor aw277866304 response:
best stick the main logic code, you couldn't see the specific question,
Most likely is the JAVA code has not closed process,

 public static int runPython (String [] param, String workName, Logger Logger) {
Int exitCode=1;
Try {
The Process proc=Runtime. GetRuntime (). The exec (param);
BufferedReader isReader=new BufferedReader (new InputStreamReader (proc. GetInputStream ()));
BufferedReader errorReader=new BufferedReader (new InputStreamReader (proc. GetErrorStream ()));
String isLine;
String errorLine;
While ((errorLine=errorReader readLine ())!=null) {
Logger. Error (workName + "error:" + errorLine);
}
While ((isLine=isReader readLine ())!=null) {
Logger. The info (workName + info: "" + isLine);
}
IsReader. Close ();
ErrorReader. Close ();
ExitCode=proc. WaitFor ();
} the catch (IOException e) {
Logger. Error (workName + "error", e);
{} catch InterruptedException (e)
Logger. Error (workName + "error", e);
} the finally {
Logger. The info (workName + "finish exitCode==" + exitCode);
}
Return exitCode;
}

CodePudding user response:

You this code itself problems,
Proc mputStream and ErrorStream process, should with the waitFor () is not in the same thread calls,
Processed waitFor is waiting for the child, the two Stream data is read the child,
Writing code is commonly, a Stream distribution one thread to process the data, the main thread calls the waitFor jammed, until the child exit and two Stream of data processing is completed, the mainline Cheng Cai will continue,

CodePudding user response:

reference, 3/f ice rain response:
you this code itself problems,
Proc mputStream and ErrorStream process, should with the waitFor () is not in the same thread calls,
Processed waitFor is waiting for the child, the two Stream data is read the child,
Writing code is commonly, a Stream distribution one thread to process the data, the main thread calls the waitFor jammed, until the child exit and two Stream of data processing is completed, the mainline Cheng Cai will continue,
if the child has been killed by the active, Java process will also because this kind of writing has been blocked here?

CodePudding user response:

A breakpoint to try not to know? Debug the
  • Related