Runtime#availableProcessors()在Linux服务器上未返回正确的结果 [英] Runtime#availableProcessors() doesn't return correct result on Linux server

查看:390
本文介绍了Runtime#availableProcessors()在Linux服务器上未返回正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常运行 Runtime#availableProcessors 来确定Windows计算机上有多少个内核,并且工作正常。结果与我在控制面板中找到的结果一致。

I usually run Runtime#availableProcessors to determine how many cores on a Windows computer and it works fine. The result is consistent with that I found from control panel.

但是,当我在Linux服务器上应用API时,它返回 1 。据我所知,服务器功能更强大,对我来说这不是一个单一的CPU系统。

However when I applied the API on a Linux server, it returns 1. As I know the server is more powerful it doesn't make sense to me it's a single cpu system.

我做了一些搜索,发现Linux机器是 Intel(R)Xeon(R)CPU X5675 @ 3.07GHz ,则谷歌搜索显示它具有 6 个cpu内核。

I did some search and found the Linux box is Intel(R) Xeon(R) CPU X5675 @ 3.07GHz, googling shows it has 6 cpu cores.

然后,问题是,为什么 Runtime#availableProcessors 误报了吗?

Then the question is, why Runtime#availableProcessors misreported? Is it a bug?

谢谢

John

这是 / proc / cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 44
model name      : Intel(R) Xeon(R) CPU           X5675  @ 3.07GHz
stepping        : 2
cpu MHz         : 3059.000
cache size      : 12288 KB
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 6118.00
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management: [8]


推荐答案

I必须是服务器的配置方式(也许您正在VM中运行)。在我的个人Linux笔记本电脑上运行时,

It must be how your server is configured (perhaps you're running in a VM). When I run, on my personal Linux laptop,

public static void main(String[] args) {
    System.out.println(Runtime.getRuntime().availableProcessors());
}

我得到

4

,因为这台机器有四个内核。并且 cat / proc / cpuinfo 报告相同。

as this machine has four cores. And cat /proc/cpuinfo reports the same.

这篇关于Runtime#availableProcessors()在Linux服务器上未返回正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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