top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is fork() and join() method in context of Java and what the difference between them?

+1 vote
578 views
What is fork() and join() method in context of Java and what the difference between them?
posted Apr 23, 2015 by Shyam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Fork-join functionality is achieved by ForkjoinTask object, it has two method fork() and join () Method.

The fork() method allows  a new ForkJoinTask to be launched from an existing one.

The join() method allows a ForkJoinTask to wait for the completion of another one.

Again ForkjoinTask object has been of two types: RecursiveAction and RecursiveTask which is more specialized form of this instance. While RecursiveAction represent executions that do not yield a return value, Instances of RecursiveTask yield return values.

The fork/join framework is an implementation of the ExecutorService interface that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively. The goal is to use all the available processing power to enhance the performance of your application.

As with any ExecutorService implementation, the fork/join framework distributes tasks to worker threads in a thread pool. The fork/join framework is distinct because it uses a work-stealing algorithm. Worker threads that run out of things to do can steal tasks from other threads that are still busy.

The center of the fork/join framework is the ForkJoinPool class, an extension of the AbstractExecutorService class. ForkJoinPool implements the core work-stealing algorithm and can execute ForkJoinTask processes.

answer Apr 24, 2015 by Karthick.c
...