0

我有 2 个 java 进程。我想通过ProcessBuilder.
我的问题是我只想启动另一个进程。我不想等待它的任何结果或输出。
即在启动第二个进程后,这两个进程将独立运行。
我怎样才能做到这一点?waitFor通过不打电话ProcessBuilder?通过不消费OutputStreams

注意:第二个过程不产生输出并“永远”运行。实际上两者都是长期运行的过程

4

2 回答 2

0

根据文档,您是否使用流程类的 waitFor 方法,如果是的话。那我想你不需要这样做。

取自Process Java Doc

**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-08T07:20:37.653 回答
0

在单独的线程中使用 ProcessBuilder 运行您的进程,在该线程中读取 stdout 和 stderr 并忽略它们,让线程在进程完成时退出

于 2013-04-08T07:22:16.353 回答