Java多线程 - 将线程分配给处理器核心 [英] Java Multithreading - Assign threads to processor cores
问题描述
我正在用java编写一个涉及并行计算的应用程序。
我的问题是我如何明确地将线程分配给核心?它的编程逻辑是什么?
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?
任何人都可以告诉为什么使用类Executor?谢谢
Can anyone tell why class Executor is used? Thanks
推荐答案
您无法将线程分配给核心。
You cannot assign threads to cores.
-
Java7的 fork / join框架解决了完全相同的问题。自动(它将设计用于多核处理器)。
Java7's fork/join framework addresses exactly the same problem. Automatically though (It will be designed for multi-core processors).
您可以做的是设置线程优先级以确定线程的优先级,如果这是您想要实现的。
What you can do is to set Thread priority to prioritize your threads, if that's what you want to achieve.
JNI可能是出口的另一个方向,但我猜是有点过分。你可以看看Peter Lawrey使用JNI的 Java-Thread-Affinity (我没有'使用它。)
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).
这篇关于Java多线程 - 将线程分配给处理器核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!