我有2個java進程。我想通過ProcessBuilder
從另一個流程啓動其中一個流程。
我的問題是我只想啓動其他進程。我不想等待任何結果或輸出。
I.e.在開始第二個過程之後,這兩個過程將獨立運行。
我該怎麼做?不要致電ProcessBuilder
上的waitFor
?通過不消耗OutputStreams
?產生另一個進程而不是等待它
注意:第二個過程不產生輸出並且「永遠」運行。其實兩者都是長時間運行的過程
我有2個java進程。我想通過ProcessBuilder
從另一個流程啓動其中一個流程。
我的問題是我只想啓動其他進程。我不想等待任何結果或輸出。
I.e.在開始第二個過程之後,這兩個過程將獨立運行。
我該怎麼做?不要致電ProcessBuilder
上的waitFor
?通過不消耗OutputStreams
?產生另一個進程而不是等待它
注意:第二個過程不產生輸出並且「永遠」運行。其實兩者都是長時間運行的過程
按照文檔,如果是的話,你使用waitFor方法的進程類。那麼我猜你不需要這樣做。
**waitFor**
public abstract int waitFor()
throws InterruptedException
causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.
Returns:
the exit value of the process. By convention, 0 indicates normal termination.
Throws:
InterruptedException - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.
使用線程。也就是說,在新線程中啓動第二個進程。 – 2013-04-08 07:17:47
你必須消耗輸出,一些進程不會退出,直到讀取輸出緩衝區,但你可以簡單地讀取流並忽略它的結果。但基本的答案是使用'線程' – MadProgrammer 2013-04-08 07:18:18
如果第二個進程不產生任何輸出並永遠運行會怎麼樣? – Jim 2013-04-08 07:20:32