How to set the CPU core affinity of Java threads?
I searched previous posts on similar topics, but I couldn't find a suitable answer, so I asked this question Thank you very much for your help in answering it
I know how to set the affinity of a process to a specific CPU kernel through the taskset command in Linux But I want to set the relationship between a java thread and a specific CPU core so that other threads belonging to the same process can run on all the remaining cores For example, if I have a process with 10 threads and a 4-core machine, I want to reserve core-1 for one thread, and the remaining 9 threads run on the remaining 3 cores Can you do it?
Thank you, Sachin
Solution
Say 2241 is the PID of your Java process Run:
jstack 2241
This gives you a list of threads Find your there and note the NID field Say NID = 0x8e9 and convert it to cardinality 10 of 2281 Then run:
taskset -p -c 0 2281
Done