Thread-launched running processes won't destroy (Java)

前端 未结 8 836
清歌不尽
清歌不尽 2021-02-01 08:41

Starting multiple threads and having each exec() then destroy() a running java process result in some of the process not being destroyed and still running after program exit. He

8条回答
  •  萌比男神i
    2021-02-01 09:27

    You should close the input/output/error streams to the process. We saw some issues in the past where the forked process was not completing properly due to those streams not being closed (even if they weren't being used).

    An exemplary solution:

    p.destroy();
    p.getInputStream().close();
    p.getOutputStream().close();
    p.getErrorStream().close();
    

提交回复
热议问题