Java - relationship between threads and CPUs

后端 未结 3 1379
遇见更好的自我
遇见更好的自我 2021-02-08 07:41

I am pretty new to multithreading, and I am working on a project where I am trying to utilize 4 CPUs in my Java program. I wanted to do something like

int numP         


        
3条回答
  •  礼貌的吻别
    2021-02-08 07:54

    no it won't guarantee anything about where the threads run

    in fact the OS thread scheduler is free to migrate threads around cores as it sees fit (so one line you could be on core 0 and the next on core 4)

    you could set the affinity of threads but this is not available in java directly (AFAIK)

提交回复
热议问题