控制 Linux 中 Java 独立运行的最大数量
我们开发了一个Java独立程序。我们已经在 Linux (RedHat ES 4) cron 中配置 安排每 10 分钟执行一次 Java 独立操作。每个独立 有时可能需要 1 小时以上才能完成,有时可能会完成 即使在5分钟之内。
我正在寻找的问题/解决方案是,执行的 Java 独立程序的数量 任何时候都不应超过,例如5个进程。所以,举例来说, 在 Java 独立/进程启动之前,如果已经有 5 个进程正在运行, 那么这个过程不应该启动;否则这会间接启动 创建 OutOfMemoryError 问题。我该如何控制这个?我还想将这 5 个进程限制配置为可配置。
其他信息:
我还配置了 -Xms 和 -Xmx 堆大小设置。
是否有任何工具/机制可以让我们控制这一点?
我还听说过 Java Service Wrapper。这是怎么回事?
We've developed a Java standalone program. We've configured in our Linux (RedHat ES 4) cron
schedule to execute this Java standalone every 10 minutes. Each standalone
may sometime take more than 1 hour to complete, or sometime it may complete
even within 5 minutes.
My problem/solution I'm looking for is, the number of Java standalones executing
at any time should not exceed, for example, 5 process. So, for example,
before even a Java standalone/process starts, if there are already 5 processes running,
then this process should not be started; otherwise this would indirectly start
creating OutOfMemoryError problems. How do I control this? I would also like to make this 5 process limit configurable.
Other Information:
I've also configured -Xms and -Xmx heap size settings.
Is there any tool/mechanism by which we can control this?
I also heard about Java Service Wrapper. What is this all about?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建 5 个空文件(名称为“1.lock”、...、“5.lock”),并让应用程序锁定其中之一来执行(如果所有文件都已锁定,则退出)。
You can create 5 empty files (with names "1.lock",...,"5.lock") and make the app to lock one of them to execute (or exit if all files are already locked).
首先,我假设您可以互换使用“线程”和“进程”这两个词。两个想法:
First, I am assuming you are using the words "thread" and "process" interchangably. Two ideas:
Java Service Wrapper 帮助您将 java 程序设置为 Windows 服务或*nix 守护进程。它并没有真正处理您正在考虑的并发问题——最接近的是一个配置设置,如果它是 Windows 服务,则不允许并发实例。
Java Service Wrapper helps you set up a java program as a Windows service or a *nix daemon. It doesn't really deal with the concurrency issue you are looking at--the closest thing is a config setting that disallows concurrent instances if its a Windows service.