Class FibonacciTask
- All Implemented Interfaces:
Serializable, Future<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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Future
Future.State -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class RecursiveTask
exec, getRawResult, setRawResultMethods inherited from class ForkJoinTask
adapt, adapt, adapt, adaptInterruptible, adaptInterruptible, adaptInterruptible, cancel, compareAndSetForkJoinTaskTag, complete, completeExceptionally, exceptionNow, fork, get, get, getException, getForkJoinTaskTag, getPool, getQueuedTaskCount, getSurplusQueuedTaskCount, helpQuiesce, inForkJoinPool, invoke, invokeAll, invokeAll, invokeAll, isCancelled, isCompletedAbnormally, isCompletedNormally, isDone, join, peekNextLocalTask, pollNextLocalTask, pollSubmission, pollTask, quietlyComplete, quietlyInvoke, quietlyJoin, quietlyJoin, quietlyJoinUninterruptibly, reinitialize, resultNow, setForkJoinTaskTag, state, tryUnfork
-
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
The primary computation logic that dictates whether to fork the problem or solve it sequentially.- Specified by:
computein classRecursiveTask<Long>- Returns:
- The computed Fibonacci sequence value.
-