[英]Java Thread Affinity lib: Why is the Affinity set to 1 << 3?
I'm looking at the Java Thread Affinity lib (link below) and in an example the affinity is set using 1 << 3
. 我正在查看Java Thread Affinity lib(下面的链接),并在示例中使用
1 << 3
设置了亲和力。 Does anyone know why this is? 有人知道为什么是这样吗?
AffinitySupport.setAffinity(1 << 3);
I would have thought it would be set to 1 or 2 for example on a 2 core machine as to say stay on core 1 or 2. I'm obviously missing something here. 我本来以为会在2核计算机上将其设置为1或2,例如说要保留在1或2核上。我显然在这里缺少了一些东西。
Link: https://github.com/peter-lawrey/Java-Thread-Affinity 链接: https : //github.com/peter-lawrey/Java-Thread-Affinity
该语法使用左移运算符: http : //processing.org/reference/leftshift.html因此,基本上1 << 3
表示二进制数为1000
,因此十进制为8
。
The argument to AffinitySupport.setAffinity()
is a bit mask. AffinitySupport.setAffinity()
的参数是位掩码。
Setting the affinity to 1 << 3
allows the the thread to run on the logical CPU #3. 将亲和力设置为
1 << 3
可使线程在逻辑CPU#3上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.