Class FibonacciTask

All Implemented Interfaces:
Serializable, Future<Long>

public class FibonacciTask extends RecursiveTask<Long>

Parallel Fibonacci (Fork/Join)

Computes the Fibonacci sequence utilizing Java's Fork/Join parallel execution model. The task recursively splits the workload into smaller asynchronous sub-tasks until a predefined granularity threshold is reached, at which point it delegates the computation to the sequential algorithm.

Author:
vicegd
See Also:
  • Constructor Details

    • FibonacciTask

      public FibonacciTask(int targetIndex)
      Initializes the parallel task.

      Note: Accepting a primitive int instead of an object instance significantly reduces heap memory allocation and Garbage Collector pressure during deep recursion.

      Parameters:
      targetIndex - The mathematical index (N) to compute.
  • Method Details

    • compute

      protected Long compute()
      The primary computation logic that dictates whether to fork the problem or solve it sequentially.
      Specified by:
      compute in class RecursiveTask<Long>
      Returns:
      The computed Fibonacci sequence value.