Home

ForkJoin

ForkJoin is a term used in parallel computing to describe a pattern and a runtime framework for dividing a problem into smaller subtasks, solving them concurrently, and then combining the results. The pattern is based on divide-and-conquer, where a task forks into multiple subtasks and later joins to reconstruct the final outcome.

In practical terms, the best-known implementation is the ForkJoin framework in Java. Introduced with Java 7

Work-stealing is a core feature of ForkJoin. Each worker thread maintains a double-ended queue of tasks and

Usage considerations include choosing appropriate task granularity to minimize overhead, as overly fine subdivisions can degrade

Historically, ForkJoin traces to the fork-join parallelism concept and gained prominence in Java 7 via the

as
part
of
the
java.util.concurrent
package,
it
provides
a
specialized
pool
called
ForkJoinPool
that
manages
worker
threads
and
supports
work-stealing.
Tasks
are
represented
by
RecursiveTask<V>
for
tasks
that
return
a
value
or
RecursiveAction
for
tasks
that
do
not.
A
computation
overrides
the
compute()
method
and
may
create
subtasks,
calling
fork()
to
schedule
them
and
join()
to
wait
for
and
obtain
their
results.
primarily
executes
its
own
tasks.
When
idle,
a
worker
may
steal
tasks
from
other
workers’
queues,
balancing
the
load
across
the
pool
and
improving
throughput
for
irregular
or
recursive
workloads.
performance.
The
framework
is
best
suited
for
CPU-bound,
compute-intensive
tasks
with
independent
subtasks
and
minimal
shared-state
synchronization.
It
is
less
appropriate
for
I/O-bound
workloads
or
tasks
with
heavy
interdependencies.
ForkJoinPool,
with
further
integration
into
parallel
streams
and
other
concurrency
utilities
in
subsequent
Java
releases.
The
general
idea—subdivide,
execute
in
parallel,
and
join—appears
in
many
languages
and
frameworks
beyond
Java.