Search code examples
javamultithreadingaffinity

Set Java Multithreading Affinity


I'm using IntelliJ with the ForkJoin framework, and am trying to benchmark two versions of my code. One is using forkjoin, one is sequential. Unfortunately, it seems that the JDK/Windows auto-distribute the sequential one across 4 cores to a certain extent. Is there a way to give a compiler directive to force affinity to only one core for the sequential version?


Solution

  • in windows you can use the task manager for this find the java.exe process and right-click (you'll need to reset this each time you restart it)

    or you'll need to make native calls to set the affinity