用于检测Java中处理器数量的平台无关方式 [英] Platform Independent Way of Detecting the Number of Processors in Java

查看:178
本文介绍了用于检测Java中处理器数量的平台无关方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种独立于平台的方法来检测Java中的物理和/或虚拟处理器的数量?一种可能的解决方案是检测操作系统并使用Windows环境变量NUMBER_OF_PROCESSORS。 Linux和Mac OS X有类似的产品吗?然而,这可能不是最佳解决方案。

Is there a platform independent way to detect the number of physical and/or virtual processors in Java? One potential solution is to detect the operating system and use the Windows environment variable "NUMBER_OF_PROCESSORS". Do Linux and Mac OS X have a similar offering? This however may not be the best solution.

推荐答案

这可能有所帮助,来自

http://www.javadb.com/get-number-可用处理器

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html

Runtime runtime = Runtime.getRuntime();
int nrOfProcessors = runtime.availableProcessors();

这篇关于用于检测Java中处理器数量的平台无关方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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