Questions tagged [fork-join]

Fork-Join means to split the work into fragments and join the results together. You can split the work into components and schedule each component to a thread pool joining the results when all components complete. You can recursively decompose an aggregate structure into identical tasks and join the results when all tasks complete.

By following the divide-and-conquer strategy, problems, such as merge sort of an array, are split into (two or more) smaller sub-problems. If these sub-problems are still too big to be solved directly, they are again recursively split into even smaller sub-problems. Once the sub-problems become small enough, a simple/naive algorithm can be used to solve them. The partial solutions of these sub-problems are then gradually combined into solutions of the original larger problems.

You can visualize the progress of the algorithm as a tree with the original problem as the root, all its direct sub-problems as the nodes right below the root, their sub-problems as the nodes further down and finally with the smallest directly solved problems as the leafs.

Trees are great data structures for parallel processing. The root node typically points to two or more child nodes. These child nodes are roots of their own sub-trees, and these sub-trees are mutually independent. Start a new parallel thread for each of the sub-trees and you are guaranteed the threads will never collide. You get thread-safety by design. This is exactly what fork/join does. Not only does it gradually divide the problem into smaller and smaller sub-problems, but it also allows these sub-problems to be processed concurrently.

As an example, you may try Java 1.7, which comes with a Fork/Join (originally referred to as jsr-166y) framework bundled.

418 questions
0
votes
3 answers

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space on eclipse

I am trying to execute this program using fork and join framework. When I feed a JPEG image of smaller size to this program it works fine, but when I give the image of size more than 4 MB it throws below exception: ****Exception in thread "main"…
Voila
  • 307
  • 2
  • 4
  • 15
0
votes
0 answers

Fork Join mechanism in Java 7

Does the scheduling mechanism implemented in Fork Join necessarily entail that if at any point of time there are free cores available, threads will definitely be scheduled on those free cores?
userx
  • 3,501
  • 5
  • 26
  • 34
0
votes
1 answer

Java 7 forking and joining

I have a main thread from which I want to spawn 2 threads to parse two different xml's. I want to know if Java 7 fork-join should be used in this scenario or the traditional way that is how we used to do in jdk 1.4 enough for this case?
-1
votes
1 answer

In Angular 9, can I adjust forkJoin so that results are processed as they are received?

I'm using Angular 9. I have the following component that displays a number of images ...
Dave
  • 17,420
  • 96
  • 300
  • 582
-1
votes
1 answer

How to correctly use forkJoin and switchMap with Promise to call two apis?

I am making an api call in Angular 9 as follows: import {SubSink} from 'subsink'; ... ... async clickButton() { for (let i = 0; i < this.Id.length; i++) { const hostId = await this.serviceA.Status(this.hostName[i]); …
meallhour
  • 9,007
  • 13
  • 36
  • 72
-1
votes
1 answer

Angular : 500 error when using forkJoin to call api services

I implement a call in the ngOnInit to two api route to get some data, I'm using angular 7 and implement forkJoin to call the api like that : ngOnInit() { debugger this.route.params.pipe( switchMap(params => forkJoin([ …
sahnoun
  • 944
  • 2
  • 22
  • 39
-1
votes
1 answer

Property 'forkJoin' does not exist on type 'typeof Observable'

I am using the old syntax of importing forkJoin, I still get this ugly error. Why does it complain? import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from…
Code Worm
  • 203
  • 1
  • 2
  • 12
-1
votes
1 answer

Does fork() call compute eventually?

My understanding is that it creates another thread and runs compute() in another thread. then join fetches the result once recursively got it. I would like to know whether fork() calls compute() or not. Thanks in advance.
Rollerball
  • 11,004
  • 22
  • 81
  • 136
-2
votes
3 answers

What is the difference between begin end and fork join with respect to non-blocking statements?

We know that the difference between blocking statements and non-blocking statements is: blocking statements executes sequentially (execution of next statement is blocked until present one completes) and are used to perform in combinational…
-2
votes
1 answer

SystemVerilog : fork - join and writing parallel testbenches

I am following the testbench example at this link: http://www.verificationguide.com/p/systemverilog-testbench-example-00.html I have two questions regarding fork-join statements. The test environment has the following tasks for initiating the test:…
tnugent97
  • 7
  • 1
-2
votes
1 answer

Fork join not giving better performance

I am trying to check performance of following code but every time I am getting sequential operation gives better performance as compared to fork join. Problem I want to find max integer: public class GetMaxIntegerProblem { private final int[]…
Ganesh Pol
  • 21
  • 2
-2
votes
1 answer

how have i to paralerize a task

I have 3 servers(debian based) in my local network. On one of them runs an app, which requires lots of CPU Power. Lets say its on server1, is it possible to provide CPU Power of Server2 and Server3 to Server1? If not, I'm thinking about programming…
-2
votes
1 answer

When is Fork/Join executor preferred to a Thread Pool executor in Java?

What example real world scenarios would justify using a fork/join executor instead of a thread pool executor in Java 7/8?
Wojtek
  • 983
  • 2
  • 10
  • 23
1 2 3
27
28