Java Multithreading - Assign threads to processor cores

前端 未结 7 1440
[愿得一人]
[愿得一人] 2020-12-18 09:42

I am writing an application in java which involves parallel computing. My question is how can I explicitly assign threads to cores? What is the programming logic for it?

相关标签:
7条回答
  • 2020-12-18 10:47

    I don't think it's easy for you to explicitly assign threads to cores. Maybe you can use native instructions, but I doubt it can be done.

    And unless you're doing some special benchmark, you really don't need to. Java threads are backed by native threads, and if the O.S. is modern enough, its kernel will dynamically assign (and re-assign) threads to cores in a way that is certainly better than yours, because it (hopefully) does load balancing.

    Start some threads that perform long computations and then see processor usage from a task manager. You'll see many cores being used.

    0 讨论(0)
提交回复
热议问题