Java中人工生成cpu负载
有没有一种简单的方法可以在 Java 中生成恒定的 CPU 负载?就像生成 60% 的 CPU 负载一样。
Is there a simple way to generate a constant CPU load in Java? Like generate CPU load at 60%.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有点晚了,但只是想分享我创建了一个名为 FakeLoad 可用于动态生成不同类型的系统负载,如 CPU、内存和磁盘 I/O。
例如,使用 FakeLoad 生成 60% 的 CPU 负载 30 秒,可以这样完成:
它不能提供完美的精度,但它能够生成相当恒定且准确的负载。它可以在 Maven Central 上找到,所以请随意尝试一下:)
Kind of late to the party, but just wanted to share that I created a small open-source client library called FakeLoad which can be used to generate different kinds of system load like CPU, memory, and disk I/O on the fly.
For instance, generating a CPU load of 60% for 30 seconds with FakeLoad can be done like this:
It doesn't provide perfect precision, but it is able to generate quite constant and accurate loads. It is available on Maven Central, so feel free to give it a try :)
尚未对此进行测试,但它可能大致有效,以使您的应用程序以正确的比例工作和睡眠。像(伪代码)这样的东西:
好的,你要求一个简单的方法,但是......:)
Have not tested this, but it might roughly work, to make your application work and sleep in the correct ratio. Something like (pseudocode):
Ok, you asked for a simple way, but ... :)
我认为这甚至是不可能的,因为:
I think that's not even possible, because: