从Java内部限制CPU [英] Throttling CPU from within Java

查看:206
本文介绍了从Java内部限制CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个(和其他)论坛上看到了很多同样题目的问题,但似乎没有一个问题可以解决我的问题。就是这样:
我有一个JVM可以占用托管它的机器上的所有CPU。我想限制它,但我不能依赖任何限制工具/技术外部到Java,因为我不能假设这个Vm将在哪里运行。因此,例如,我不能使用处理器亲和性,因为如果VM在Mac上运行,操作系统将不会使进程关联可用。

I have seen many questions in this (and others) forum with the same title, but none of them seemed to address exactly my problem. This is it: I have got a JVM that eats all the CPU on the machine that hosts it. I would like to throttle it, however I cannot rely on any throttling tool/technique external to Java as I cannot make assumptions as to where this Vm will be run. Thus, for instance, I cannot use processor affinity because if the VM runs on a Mac the OS won't make process affinity available.

我需要的是一个指示至于是否存在 Java中以确保线程不占用完整的CPU。

What I would need is an indication as to whether means exist within Java to ensure the thread does not take the full CPU.

我想直接说明我不能使用一些论坛中建议的基于交替流程执行和暂停的技术,因为线程需要不断生成值。

I would like to point straightaway that I cannot use techniques based on alternating process executions and pauses, as suggested in some forums, because the thread needs to generate values continuously.

理想情况下我想要一些意思,例如,设置一些VM或线程优先级,或以某种方式限制CPU消耗的百分比。

Ideally I'd like some mean for, for instance, setting some VM or thread priority, or cap in some way the percentage of CPU consumed.

任何帮助将不胜感激。

推荐答案

非常有趣的帖子。我发现Java没有提供做我想做的事情的方法,唯一的方法是从外部 JVM。
我最终使用 nice 来改变我的测试(Linux)环境中的调度优先级,仍然需要为基于WIn的操作系统找到类似的东西。

Really interesting thread. I found out Java does not provide means for doing what I want to do, and the only way to do this is from outside the JVM. I ended up using nice to alter the scheduling priority in my test (Linux) environment, will still need to find something similar for WIn-based OSs.

非常感谢每个人的干预。

Everyone's intervention has been much appreciated.

这篇关于从Java内部限制CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆