优秀的 Java 进程控制库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/193166/
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
Good Java Process Control Library
提问by Taylor Gautier
Java process control is notoriously bad - primarily due to inadequate support by the Java VM/JDK classes (e.g. java.lang.Process).
Java 进程控制是出了名的糟糕——主要是由于 Java VM/JDK 类(例如 java.lang.Process)的支持不足。
I am wondering, are there any good open source libraries out there that are reliable.
我想知道,是否有任何可靠的开源库。
The requirements would be:
要求是:
- OSS
- Start/Stop processes
- Manage STDIN and STDOUT
- cross platform (at least Linux, Windows, Solaris, HP, and IBM in that order)
- (optional) restartable
- (desirable) mature
- 开源软件
- 启动/停止进程
- 管理标准输入和标准输出
- 跨平台(至少按 Linux、Windows、Solaris、HP 和 IBM 的顺序)
- (可选)可重启
- (可取的)成熟
采纳答案by Trenton
Java Service Wrappermight be what you're looking for. It's cross-platform, can be used to start things as a Windows service, capture IO, and generally completely manage any java app. It's very light weight and well designed. Atlassian uses it to wrap their products (Jira, Bamboo, etc), so it's battle tested.
Java Service Wrapper可能正是您要找的。它是跨平台的,可用于将事物作为 Windows 服务启动,捕获 IO,并且通常完全管理任何 Java 应用程序。它的重量非常轻,设计精良。Atlassian 使用它来包装他们的产品(Jira、Bamboo 等),因此它经过了实战测试。
回答by Michelle Tilley
How about Apache Commons Exec?
回答by Ryan
One more requirement... cross platform support for killing of an orphaned process. With java.lang.Process
(and Apache Commons Exec), there is no way to kill external processes when the Java application does a hard stop (kill -9). I'd really like to find a library that can handle the problem better.
还有一个要求……支持杀死孤立进程的跨平台支持。使用java.lang.Process
(和 Apache Commons Exec),当 Java 应用程序执行硬停止(kill -9)时,无法终止外部进程。我真的很想找到一个可以更好地处理问题的库。
One solution may be to store PIDs in some resource on disk, and then kill the processes on restart of the Java application. Of course, this would be platform dependent, so good a cross platform library would be fantastic.
一种解决方案可能是将 PID 存储在磁盘上的某个资源中,然后在重新启动 Java 应用程序时终止进程。当然,这将取决于平台,所以好的跨平台库会很棒。