Java 多核处理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14142461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Multi-Core Processing
提问by Get Off My Lawn
I would like to learn about Java's multi-core processing. From what I understand, is that Threading
is one type of multi-core, which I feel I have a decent grasp of. I know there are other ways to do multi-core processing, but I don't know what they are. Does anyone know of any good simple tutorials/examples, or have their own that I could look at to learn more about multi-core processing in Java?
我想了解Java的多核处理。据我了解,这Threading
是一种多核,我觉得我有一个不错的把握。我知道还有其他方法可以进行多核处理,但我不知道它们是什么。有没有人知道任何好的简单教程/示例,或者有自己的教程/示例,我可以查看以了解有关 Java 多核处理的更多信息?
All the tutorials that I have found get too in depth with charts, graphs, background information, etc. and that really isn't my learning style with programming. I would preferably like something quick and simple.
我发现的所有教程在图表、图形、背景信息等方面都过于深入,这真的不是我的编程学习风格。我更喜欢快速简单的东西。
回答by Peter Lawrey
The primary way you use multiple cores is to use multiple threads. The simplest way to use these if via the High Level Concurrency Objectswhich you should be familar with. This uses threads but you don't have to deal with them directly.
使用多核的主要方式是使用多线程。使用这些的最简单方法是通过您应该熟悉的高级并发对象。这使用线程,但您不必直接处理它们。
Another way is to use multiple processes, but this is an indirect way of using multiple threads.
另一种方式是使用多进程,但这是使用多线程的间接方式。
You might find this library interesting. Java Thread AffinityIt allows you to assign thread to sockets, cores or cpus.
您可能会发现这个库很有趣。Java Thread Affinity它允许您将线程分配给套接字、内核或 CPU。
回答by Evgeniy Dorofeev
This is Oracle's tutorial about Java 7 fork/join framework
这是 Oracle 关于 Java 7 fork/join 框架的教程
http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
回答by Alexei Kaigorodov
Beyond the mentioned High Level Concurrency Objects (fork/join should be added there) which are part of the Java implementation, there are many libraries and frameworks. Google for "actor framework", "dataflow framework", mapreduce, "scientific dataflow". The dataflow model is the mainstream, all other are it's variations (e.g. actor - dataflow node with single input port, mapreduce - persistent distributed actors created by demand, etc). The minimal dataflow framework (no persistence or distribution over a machine cluster) is mine df4jlibrary.
除了作为 Java 实现一部分的上述高级并发对象(应该在那里添加 fork/join)之外,还有许多库和框架。谷歌搜索“actor 框架”、“数据流框架”、mapreduce、“科学数据流”。数据流模型是主流,所有其他模型都是它的变体(例如,actor - 具有单个输入端口的数据流节点,mapreduce - 按需创建的持久分布式actor 等)。最小的数据流框架(在机器集群上没有持久性或分布)是我的df4j库。