在Java中是否有办法找出安装了多少CPU(或内核)? [英] Is there a way in Java to find out how many CPUs (or cores) are installed?
本文介绍了在Java中是否有办法找出安装了多少CPU(或内核)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对多线程程序进行一些调整。
I want to make some tuning for multithreaded program.
如果我知道线程可以并行工作多少,我可以使程序更有效。
If I know how much threads can really work in parallel I can make the program much more effective.
Java中是否有办法获取此信息?
Is there a way in Java to get this info?
推荐答案
你可以使用
Runtime.getRuntime().availableProcessors()
但它更像是一个最好的猜测甚至提到通过API
But its more of a best guess and even mentioned by the API
在虚拟
计算机的特定调用期间,此值可能会更改。因此,对可用
处理器数量敏感的应用程序应偶尔轮询此属性并适当调整其资源使用情况
。
This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjust their resource usage appropriately.
这篇关于在Java中是否有办法找出安装了多少CPU(或内核)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文