fork-join

ForkJoinTask vs CompletableFuture

為{幸葍}努か 提交于 2019-12-08 15:59:03
问题 In Java 8 there are two ways of starting asynchronous computations - CompletableFuture and ForkJoinTask . They both seem fairly similar - the inner classes of CompletableFuture even extend ForkJoinTask . Is there a reason to use one over the other? One key difference that I can see is that the CompletableFuture.join method simply blocks until the future is complete ( waitingGet just spins using a ManagedBlocker ), whereas a ForkJoinTask.join can steal work off the queue to help the task you

Use fork/join or decision/merge nodes in an activity diagram for modelling user choices?

荒凉一梦 提交于 2019-12-08 13:29:47
问题 I was trying to use the activity diagram to model user interactions with a GUI, and came across the following question: whether to use decision/merge nodes or fork/join nodes in modelling different user choices. For example, a user can either change the settings of the program by clicking a button, or launch a process by clicking another button. It seemed to me using decision/merge nodes and a control arrow pointing back to the decision node is more natural, as the choices cannot be taken in

How to Block a Queue in ForkJoinPool?

不想你离开。 提交于 2019-12-07 11:52:29
问题 I need to block threads on ForkJoinPool when its queue is full. This can be done in the standard ThreadPoolExecutor, e.g.: private static ExecutorService newFixedThreadPoolWithQueueSize(int nThreads, int queueSize) { return new ThreadPoolExecutor(nThreads, nThreads, 5000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy()); } I know, there is some Dequeue inside ForkJoinPool, but I don't have access to it via its API. Update:

How can I show that in Java Fork/Join framework work-stealing occurs?

戏子无情 提交于 2019-12-06 10:20:14
问题 I would like to improve my fork/join little example to show that during Java Fork/Join framework execution work stealing occurs. What changes I need to do to following code? Purpose of example: just do a linear research of a value breaking up work between multiple threads. package com.stackoverflow.questions; import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.RecursiveTask; public class CounterFJ<T

Memory visibility in Fork-join

丶灬走出姿态 提交于 2019-12-06 01:37:27
问题 Brian Goetz's wrote a nice article on fork-join at http://www.ibm.com/developerworks/java/library/j-jtp03048.html. In it, he lists a merge sort algorithm using the fork-join mechanism, in which he performs the sort on two sides of an array in parallel, then merges the result. The algorithm sorts on two different sections of the same array simultaneously. Why isn't an AtomicIntegerArray or some other mechanism necessary to maintain visibility? What guarantee is there that one thread will see

How to Block a Queue in ForkJoinPool?

╄→гoц情女王★ 提交于 2019-12-06 00:32:29
I need to block threads on ForkJoinPool when its queue is full. This can be done in the standard ThreadPoolExecutor, e.g.: private static ExecutorService newFixedThreadPoolWithQueueSize(int nThreads, int queueSize) { return new ThreadPoolExecutor(nThreads, nThreads, 5000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy()); } I know, there is some Dequeue inside ForkJoinPool, but I don't have access to it via its API. Update: Please see the answer below. After some research I am happy to answer the question: Reason: There is no

A light weight Scala fork join syntax

China☆狼群 提交于 2019-12-05 21:22:38
Despite the upcoming java 7 standard fork/join framework, I am building some helper method that is light weight in syntax for client to run code in parallel. Here is a runnable main method to illustrate the idea. import actors.Futures object ForkTest2 { def main(args: Array[String]) { test1 test2 } def test1 { val (a, b, c) =fork({ Thread.sleep(500) println("inside fx1 ",+System.currentTimeMillis) true }, { Thread.sleep(1000) println("inside fx2 ",+System.currentTimeMillis) "stringResult" }, { Thread.sleep(1500) println("inside fx3 ",+System.currentTimeMillis) 1 }) println(b, a, c) true } def

Error rxjs_Observable__.Observable.forkJoin is not a function?

无人久伴 提交于 2019-12-04 18:07:50
问题 I am using Rxjs in an angualr-cli application. in viewer.component.ts //Other Imports import { Observable } from 'rxjs/Observable'; //omitting for brevity export class ViewerComponent implements OnInit, AfterViewInit, OnDestroy { someFunction(someArg){ //omitting for brevity let someArray: any = []; //Add some info Observable.forkJoin(someArray).subscribe(data => { //Do something with data }); } //omitting for brevity } I get and error as ERROR TypeError: __WEBPACK_IMPORTED_MODULE_2_rxjs

Java 7: Fork/Join Framework

让人想犯罪 __ 提交于 2019-12-04 08:05:12
问题 Can someone explain what Fork/Join is? 回答1: 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

Memory visibility in Fork-join

荒凉一梦 提交于 2019-12-04 06:08:12
Brian Goetz's wrote a nice article on fork-join at http://www.ibm.com/developerworks/java/library/j-jtp03048.html . In it, he lists a merge sort algorithm using the fork-join mechanism, in which he performs the sort on two sides of an array in parallel, then merges the result. The algorithm sorts on two different sections of the same array simultaneously. Why isn't an AtomicIntegerArray or some other mechanism necessary to maintain visibility? What guarantee is there that one thread will see the writes done by the other, or is this a subtly bug? As a follow up, does Scala's ForkJoinScheduler