RecursiveAction is an abstract class encapsulates a task that does not return a result. It is a subclass of ForkJoinTask, which is an abstract class representing a task that can be executed on a separate core in a multicore system. The RecursiveAction class is extended to create a task that has a void return type. The code that represents the computational portion of the task is kept within the compute() method of RecursiveAction.
RecursiveAction is used for tasks that can be divided and executed parallelly. These tasks should not return any value. For example, sorting a large array can be easily implemented with RecursiveAction, with the array being divided into small manageable chunks and each part being sorted on a separate core.
java.lang.Object ↳ java.util.concurrent.ForkJoinTask<Void> ↳ java.util.concurrent.RecursiveAction
Constructor of RecursiveAction:
RecursiveAction: Creates an object of RecursiveAction with default settings.
- compute()– It is the method that does the computation performed by the task.
protected abstract void compute()
exec()– This method implements the basic rules necessary for the execution of a task for RecursiveAction.
protected final boolean exec()
getRawResult()– The function returns the task completion status. It always returns null.
public final Void getRawResult()
setRawResult()– The function sets the task completion status, to the value passed in the argument.
protected final void setRawResult(Void mustBeNull)
Example: To demonstrate RecursiveAction class
A portion of the original sequence 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 A portion of the transformed sequence (to four decimal places): 0.0000 1.0000 1.4142 1.7321 2.0000 2.2361 2.4495 2.6458 2.8284
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java.lang.Class class in Java | Set 1
- Java.lang.Class class in Java | Set 2
- Using predefined class name as Class or Variable name in Java
- Java.util.TimeZone Class (Set-2) | Example On TimeZone Class
- Implement Pair Class with Unit Class in Java using JavaTuples
- Implement Triplet Class with Pair Class in Java using JavaTuples
- Implement Quintet Class with Quartet Class in Java using JavaTuples
- Implement Quartet Class with Triplet Class in Java using JavaTuples
- Implement Octet Class from Septet Class in Java using JavaTuples
- Implement Ennead Class from Octet Class in Java using JavaTuples
- Implement Sextet Class from Quintet Class in Java using JavaTuples
- Implement Septet Class from Sextet Class in Java using JavaTuples
- Implement Decade Class from Ennead Class in Java using JavaTuples
- Difference between Abstract Class and Concrete Class in Java
- In Java, Can we call the main() method of a class from another class?
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.util.BitSet class in Java with Examples | Set 1
- Java.util.concurrent.Phaser class in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java.awt.image.RescaleOp Class in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.