参考:https://mp.weixin.qq.com/s/494wqyxyFzDuGwG_51tFbQ
<dependency>
<groupId>net.openhft</groupId>
<artifactId>affinity</artifactId>
<version>3.20.0</version>
</dependency>
public static void main(String[] args) {
try (AffinityLock affinityLock = AffinityLock.acquireLock(3)) {
// do some work while locked to a CPU.
while (true) {
}
}
}