简体   繁体   中英

Why Fork/Join framework was introduced when all JAVA threads are Native threads created using OS libraries?

What I know is after JDK 1.2 all Java Threads are created using 'Native Thread Model' which associates each Java Thread with an OS thread with the help of JNI and OS Thread library.

So from the following text I believe that all Java threads created nowadays can realize use of multi-core processors:

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.

But when I read about the introduction of Fork/Join Framework introduced in JDK 7 in JAVA The Compelete Reference :

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.

It makes me question why the framework was introduced when 'Java Native Thread Model' existed since JDK 3?

Fork join framework does not replace the original low level thread API; it makes it easier to use for certain classes of problems.

The original, low-level thread API works : you can use all the CPUs and all the cores on the CPUs installed on the system. If you ever try to actually write multithreaded applications, you'll quickly realize that it is hard.

The low level thread API works well for problems where threads are largely independent, and don't have to share information between each other - in other words, embarrassingly parallel problems . Many problems however are not like this. With the low level API, it is very difficult to implement complex algorithms in a way that is safe (produces correct results and does not have unwanted effects like dead lock) and efficient (does not waste system resources).

The Java fork/join framework, an implementation on the fork/join model , was created as a high level mechanism to make it easier to apply parallel computing for divide and conquer algorithms .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM