每个处理器的线程数 [英] Threads per Processor

查看:160
本文介绍了每个处理器的线程数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,是否有一种编程方式来找出CPU支持多少并发线程?



更新 >

为了说明,我不是试图用线程敲CPU,我知道Runtime.getRuntime()。availableProcessors()函数,它提供我的一部分信息



我想知道是否有一种方法可以自动调整线程池的大小,以便:




  • 如果我在一个1岁的服务器上运行,我得到2个线程(每个CPU x 1个线程,任意乘数2)

  • <如果我从两年后切换到一个Intel i7四核心(每个核心支持2个线程),我得到16个线程(每个CPU 2个逻辑线程,4个CPU x任意乘数2)。
  • 如果使用八核心Ultrasparc T2服务器(每个核心支持8个线程),我得到128个线程(每个CPU 8个线程x 8个CPU x任意乘数2)

  • 如果我在30个不同机器的集群上部署相同的软件,可能在不同的年份购买,我不需要读取CPU规格,并为每个机器设置配置选项。 li>

解决方案

Runtime.availableProcessors返回逻辑处理器的数量硬件线程)而不是物理内核。请参见 CR 5048379


In Java, is there a programmatic way to find out how many concurrent threads are supported by a CPU?

Update

To clarify, I'm not trying to hammer the CPU with threads and I am aware of Runtime.getRuntime().availableProcessors() function, which provides me part of the information I'm looking for.

I want to find out if there's a way to automatically tune the size of thread pool so that:

  • if I'm running on a 1-year old server, I get 2 threads (1 thread per CPU x an arbitrary multiplier of 2)
  • if I switch to an Intel i7 quad core two years from now (which supports 2 threads per core), I get 16 threads (2 logical threads per CPU x 4 CPUs x the arbitrary multiplier of 2).
  • if, instead, I use a eight core Ultrasparc T2 server (which supports 8 threads per core), I get 128 threads (8 threads per CPU x 8 CPUs x the arbitrary multiplier of 2)
  • if I deploy the same software on a cluster of 30 different machines, potentially purchased at different years, I don't need to read the CPU specs and set configuration options for every single one of them.

解决方案

Runtime.availableProcessors returns the number of logical processors (i.e. hardware threads) not physical cores. See CR 5048379.

这篇关于每个处理器的线程数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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