Some history
Until recently, most computers only had 1 processing core
Multithreading was simulated on a single core
Not true concurrency
Serial approach to algorithms often sufficed
multicore
Concurrency and performance are tied together
Real concurrency –separate threads can execute on different
cores at the same time
The JVM runtime controls scheduling
Fork and Join Framework
Some types of algorithms exist that require tasks to create subtasks
and communicate with each other to complete.
Those are the “divide and conquer” algorithms, which are also
referred to as “map and reduce,”
Example: partial sums of an Array of Integers
Divide the array into the number n of available physical processing units
Create Callable instances to compute each partial sum
Submit them to an executor managing a pool of n threads
Collect the result to compute the final sum
Fork Join
The core addition is a new ForkJoinPool executor that is dedicated to running
instances implementing ForkJoinTask.
ForkJoinTask objects feature two specific methods:
fork(): allows a ForkJoinTask to be planned for asynchronous execution
join() method allows a ForkJoinTask to wait for the completion of another one
There are 2 types of ForkJoinTask:
RecursiveAction represent executions that do not yield a return value
Instances RecursiveTask yields return values