fork-join

【转】JDK 7 中的 Fork/Join 模式

[亡魂溺海] 提交于 2019-12-03 08:02:07
介绍 随着多核芯片逐渐成为主流,大多数软件开发人员不可避免地需要了解并行编程的知识。而同时,主流程序语言正在将越来越多的并行特性合并到标准库或者语言本身之中。我们可以看到,JDK 在这方面同样走在潮流的前方。在 JDK 标准版 5 中,由 Doug Lea 提供的并行框架成为了标准库的一部分(JSR-166)。随后,在 JDK 6 中,一些新的并行特性,例如并行 collection 框架,合并到了标准库中(JSR-166x)。直到今天,尽管 Java SE 7 还没有正式发布,一些并行相关的新特性已经出现在 JSR-166y 中: Fork/Join 模式; TransferQueue,它继承自 BlockingQueue 并能在队列满时阻塞“生产者”; ArrayTasks/ListTasks,用于并行执行某些数组/列表相关任务的类; IntTasks/LongTasks/DoubleTasks,用于并行处理数字类型数组的工具类,提供了排序、查找、求和、求最小值、求最大值等功能; 其中,对 Fork/Join 模式的支持可能是对开发并行软件来说最通用的新特性。在 JSR-166y 中,Doug Lea 实现 ArrayTasks/ListTasks/IntTasks/LongTasks/DoubleTasks 时就大量的用到了 Fork/Join 模式。读者还需要注意一点,因为

Detailed difference between Java8 ForkJoinPool and Executors.newWorkStealingPool?

♀尐吖头ヾ 提交于 2019-12-03 05:08:31
问题 What is the low-level difference among using: ForkJoinPool = new ForkJoinPool(X); and ExecutorService ex = Executors.neWorkStealingPool(X); Where X is the desired level of parallelism i.e threads running.. According to the docs I found them similar. Also tell me which one is more appropriate and safe under any normal uses. I have 130 million entries to write into a BufferedWriter and Sort them using Unix sort by 1st column. Also let me know how many threads to keep if possible. Note: My

Is Java's fork-and-join thread pool is good for executing IO bound task?

梦想的初衷 提交于 2019-12-03 04:50:43
问题 in my application, I have to solve a problem by executing many network-io bound task and sometime one io bound task and be divided into smaller io bound tasks. These tasks are currently getting executed using Java's standard threadpool mechanism. I am wondering whether I can move to fork-and-join framework? But the question is, is forkandjoin framework usually being used to solve io bound operations or CPU bound? I assume they are mostly for CPU bound operations cause fork-and-join framework

Java 7: Fork/Join Framework

耗尽温柔 提交于 2019-12-02 20:50:26
Can someone explain what Fork/Join is? Fork Join is a new framework that has an easier to use API for a parallel, divide and conquer algorithm. Say you have a long running task that, for this instance, has a complicated algorithm. You would want to fork the large tasks and now work on those two tasks. Now lets say that that those two tasks are still too big, you would fork each into two tasks (at this point there are four). You would continue this until each task is at an acceptable size and invoke the algorithm. It is important to know the invocation of each task is done in parallel. When the

Detailed difference between Java8 ForkJoinPool and Executors.newWorkStealingPool?

落爺英雄遲暮 提交于 2019-12-02 18:22:50
What is the low-level difference among using: ForkJoinPool = new ForkJoinPool(X); and ExecutorService ex = Executors.neWorkStealingPool(X); Where X is the desired level of parallelism i.e threads running.. According to the docs I found them similar. Also tell me which one is more appropriate and safe under any normal uses. I have 130 million entries to write into a BufferedWriter and Sort them using Unix sort by 1st column. Also let me know how many threads to keep if possible. Note: My System has 8 core processors and 32 GB RAM. Work stealing is a technique used by modern thread-pools in

Is Java's fork-and-join thread pool is good for executing IO bound task?

∥☆過路亽.° 提交于 2019-12-02 18:05:06
in my application, I have to solve a problem by executing many network-io bound task and sometime one io bound task and be divided into smaller io bound tasks. These tasks are currently getting executed using Java's standard threadpool mechanism. I am wondering whether I can move to fork-and-join framework? But the question is, is forkandjoin framework usually being used to solve io bound operations or CPU bound? I assume they are mostly for CPU bound operations cause fork-and-join framework makes use of work stealing technique to make use of multo core processors, but if I use it for IO bound

Strange output when using JMH

心已入冬 提交于 2019-12-01 22:53:44
I'm using jmh to benchmark a simple application (from SO question Unexpected Scalability results in java fork-join ) using maven and following the command-line approach as advised in http://openjdk.java.net/projects/code-tools/jmh/ . After successfully setting up and building the benchmark, I get the following benchmark results using the avgt mode: C:\Users\username\my-app\test>java -jar target/benchmarks.jar -bm avgt -f 1 # JMH 1.10.1 (released 13 days ago) # VM invoker: C:\Program Files\Java\jre1.8.0_45\bin\java.exe # VM options: <none> # Warmup: 20 iterations, 1 s each # Measurement: 20

scala.concurrent.forkjoin.ForkJoinPool vs java.util.concurrent.ForkJoinPool

余生长醉 提交于 2019-12-01 03:30:57
Why ForkJoinPool was forked for Scala? Which implementation and for which case is preferred? The obvious reason for the scala library to have its own copy of ForkJoinPool is that scala must run on pre-1.7 JVMs, and ForkJoinPool was only introduced in Java 1.7. In addition, there were a few changes made for internal (scala) use, such as this: https://github.com/scala/scala/commit/76e9da2ca4c31daec2b04848c3c2dbad6ecd426e Given that scala's version will probably not give you any advantage (if you are compiling and running against java 1.7), I'd say that for you own use you should probably use

ForkJoinPool stalls during invokeAll/join

核能气质少年 提交于 2019-11-30 09:59:08
I try to use a ForkJoinPool to parallelize my CPU intensive calculations. My understanding of a ForkJoinPool is, that it continues to work as long as any task is available to be executed. Unfortunately I frequently observed worker threads idling/waiting, thus not all CPU are kept busy. Sometimes I even observed additional worker threads. I did not expect this, as I strictly tried to use non blocking tasks. My observation is very similar to those of ForkJoinPool seems to waste a thread . After debugging a lot into ForkJoinPool I have a guess: I used invokeAll() to distribute work over a list of

How to use MDC with ForkJoinPool?

半世苍凉 提交于 2019-11-30 09:27:54
Following up on How to use MDC with thread pools? how can one use MDC with a ForkJoinPool ? Specifically, I how can one wrap a ForkJoinTask so MDC values are set before executing a task? The following seems to work for me: import java.lang.Thread.UncaughtExceptionHandler; import java.util.Map; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; import java.util.concurrent.atomic.AtomicReference; import org.slf4j.MDC; /** * A {@link ForkJoinPool} that inherits MDC contexts from the thread that queues a task. * * @author Gili Tzabari */ public final class