Java - C-Like Fork?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/287633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:35:58  来源:igfitidea点击:

Java - C-Like Fork?

javacfork

提问by sakana

Is it possible to do a "C like" fork in java, using an new independent jvm process ?

是否可以使用新的独立 jvm 进程在 Java 中执行“类似 C”的 fork?

How?

如何?

采纳答案by PhiLho

Funnily, I am just working on this: a Java process running other Java processes. I used the article From Runtime.exec() to ProcessBuilderas a solid base, and When Runtime.exec() won'tas a good advice how to gobble the output streams.

有趣的是,我只是在研究这个:一个运行其他 Java 进程的 Java 进程。我使用文章From Runtime.exec() to ProcessBuilder作为坚实的基础,而When Runtime.exec() 不会作为如何吞噬输出流的好建议。

PS.: For those wondering, I had to do that (instead of spawning new threads) because yet another Java process is checking the presence of these processes which are, normally, ran separately with shell commands.

PS.:对于那些想知道的人,我必须这样做(而不是产生新线程),因为另一个 Java 进程正在检查这些进程的存在,这些进程通常使用 shell 命令单独运行。

回答by user525362

This answer is probably a little late but:

这个答案可能有点晚了,但是:

http://akuma.kohsuke.org/

http://akuma.kohsuke.org/

seems to be exactly what your looking for

似乎正是您要找的

回答by Markus Malkusch

The Application Isolation API (JSR 121)introduces Isolatewhich addresses this use case.

应用程序隔离API(JSR 121)介绍Isolate其中涉及该使用情况。