我在java.Multiple进程中使用ProcessBuilder启动了一个进程.如果我想停止一个进程.如何停止进程.
public void terminalExecute(String builder) throws InterruptedException { System.out.println(builder); String[] splits = builder.split(" "); System.out.println(splits.length); ProcessBuilder pb = new ProcessBuilder(splits[0],splits[1],splits[2],splits[3],splits[4],splits[5],splits[6],splits[7]); Process p = null ; pb.redirectErrorStream(true); try { p = pb.start(); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String s = ""; while((s = in.readLine()) != null){ System.out.println(s); } int status = p.waitFor(); System.out.println("Exited with status: " + status); } catch (IOException e) { e.printStackTrace(); } }
在另一类称为我喜欢这个函数:字符串CMD = "java的-Xmx3024m -XX:MaxPermSize参数=512米-Xms1024m -cp "+ ConfReader.getABDFJarPath()+" edu.am.abdf.core.StrWorkflow" +新的BigInteger(serviceRequest .getBytes()); ProcessExecutor procExec = new ProcessExecutor(); procExec.terminalExecute(CMD); 那么,我如何在这个课程中获得进程ID?
start()
ProcessBuilder
返回Process
实例的方法.你可以destroy()
在上面调用方法.
请参阅:https://docs.oracle.com/javase/7/docs/api/java/lang/Process.html