Java Multithreading - Assign threads to processor cores

前端 未结 7 1444
[愿得一人]
[愿得一人] 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条回答
  •  梦毁少年i
    2020-12-18 10:34

    You cannot assign threads to cores.

    1. Java7's fork/join framework addresses exactly the same problem. Automatically though (It will be designed for multi-core processors).

    2. What you can do is to set Thread priority to prioritize your threads, if that's what you want to achieve.

    3. JNI might be another direction to export, but an overkill I guess. You can look at Peter Lawrey's Java-Thread-Affinity which uses JNI (I haven't used it).

提交回复
热议问题