gpt4 book ai didi

java - 什么不适用于 ProcessBuilder 和 Daemons

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:41 24 4
gpt4 key购买 nike

在 ProcessBuilder 的 JavaDoc 上它指出

The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on
Microsoft Windows, or shell scripts.

我的主要问题是 ProcessBuilder 不能很好地与守护进程一起工作是怎么回事? ProcessBuilder 不适合作为启动这些类型的应用程序的可接受方式怎么办?

谢谢!

最佳答案

我的猜测(基于我在 code grep 中找到的评论)是问题在于您必须处理流程的流,并且这种处理可能是一个问题。

The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard I/O (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream(), getInputStream(), getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

这也可能与 Process 是一个抽象类这一事实有关,每个 JRE/JDK 都带有它自己的平台相关进程实现(例如 UNIXProcessWindowsProcess 等)一些操作系统可能只是具有与打开进程相关的限制,Java 无法在其文档中涵盖这些限制。

再次强调 - 这只是一个猜测,代码并没有透露太多信息。

根据我的经验(在 *nix 系统和 Windows 上)- 在构建命令行的方式、提供参数的方式(在 arguments 参数或在命令行中)以及如何构建衍生进程的环境(继承进程的值或自行创建)。无论如何,这更像是一种反复试验的游戏。

关于java - 什么不适用于 ProcessBuilder 和 Daemons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com