为什么在所有 JAVA 线程都是使用 OS 库创建的本机线程时引入 Fork/Join 框架?
Why Fork/Join framework was introduced when all JAVA threads are Native threads created using OS libraries?
我所知道的是 JDK 1.2 所有 Java 线程都是使用 'Native Thread Model' 创建的,它将每个 Java 线程与一个 OS 线程相关联JNI 和 OS 线程库的帮助。
所以从下面text我相信现在创建的所有Java线程都可以实现多核处理器的使用:
Multiple native threads can coexist. Therefore it is also called many-to-many model. Such characteristic of this model allows it to take complete advantage of multi-core processors and execute threads on separate individual cores concurrently.
但是当我在JAVA The Compelete Reference中看到Fork/Join Framework introduction in JDK 7的介绍时:
Although the original concurrent API was impressive in its own right, it was significantly expanded by JDK 7. The most important addition was the Fork/Join Framework. The Fork/Join Framework facilitates the creation of programs that make use of multiple processors (such as those found in multicore systems). Thus, it streamlines the development of programs in which two or more pieces execute with true simultaneity (that is, true parallel execution), not just time-slicing.
这让我质疑为什么在 'Java Native Thread Model' 自 JDK 3 以来就存在时引入框架?
fork join框架不替代原有的底层线程API;它使解决某些 类 问题变得更容易。
原始的低级线程API works:您可以使用系统上安装的所有CPU和CPU上的所有内核。如果您曾经尝试实际编写多线程应用程序,您很快就会意识到这很难。
低级线程 API 适用于线程在很大程度上独立且彼此之间不必共享信息的问题 - 换句话说,embarrassingly parallel problems。然而很多问题不是这样的。使用低级别 API,很难以 安全 的方式实现复杂算法(产生正确的结果并且不会产生死锁等不良影响)和 高效(不浪费系统资源)。
Java fork/join 框架,fork/join model, was created as a high level mechanism to make it easier to apply parallel computing for divide and conquer algorithms.
上的实现
我所知道的是 JDK 1.2 所有 Java 线程都是使用 'Native Thread Model' 创建的,它将每个 Java 线程与一个 OS 线程相关联JNI 和 OS 线程库的帮助。
所以从下面text我相信现在创建的所有Java线程都可以实现多核处理器的使用:
Multiple native threads can coexist. Therefore it is also called many-to-many model. Such characteristic of this model allows it to take complete advantage of multi-core processors and execute threads on separate individual cores concurrently.
但是当我在JAVA The Compelete Reference中看到Fork/Join Framework introduction in JDK 7的介绍时:
Although the original concurrent API was impressive in its own right, it was significantly expanded by JDK 7. The most important addition was the Fork/Join Framework. The Fork/Join Framework facilitates the creation of programs that make use of multiple processors (such as those found in multicore systems). Thus, it streamlines the development of programs in which two or more pieces execute with true simultaneity (that is, true parallel execution), not just time-slicing.
这让我质疑为什么在 'Java Native Thread Model' 自 JDK 3 以来就存在时引入框架?
fork join框架不替代原有的底层线程API;它使解决某些 类 问题变得更容易。
原始的低级线程API works:您可以使用系统上安装的所有CPU和CPU上的所有内核。如果您曾经尝试实际编写多线程应用程序,您很快就会意识到这很难。
低级线程 API 适用于线程在很大程度上独立且彼此之间不必共享信息的问题 - 换句话说,embarrassingly parallel problems。然而很多问题不是这样的。使用低级别 API,很难以 安全 的方式实现复杂算法(产生正确的结果并且不会产生死锁等不良影响)和 高效(不浪费系统资源)。
Java fork/join 框架,fork/join model, was created as a high level mechanism to make it easier to apply parallel computing for divide and conquer algorithms.
上的实现