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

前端 未结 8 741
清歌不尽
清歌不尽 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条回答
  •  鱼传尺愫
    2021-02-01 09:19

    Use a p.waitFor(); before p.destroy(); ,

    this will ensure the completion of the previous process. I think you p.destroy command gets invoked sooner than the exec() command performs the action. Therefore it becomes useless.

提交回复
热议问题