Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between recursive task and recursive action in ForkJoinPool

We can submit two types of tasks to forkJoinPool. one is RecursiveAction and other is RecursiveTask.

What is the difference between both of them?

like image 786
Niraj Sonawane Avatar asked Jun 12 '18 12:06

Niraj Sonawane


2 Answers

From the first lines of their respective Javadocs:

  • [RecursiveTask is] A recursive result-bearing ForkJoinTask.
  • [RecursiveAction is] A recursive resultless ForkJoinTask.

Although technically, RecursiveAction does return a value, it's just always null, because it's a ForkJoinTask<Void>, and that's the only possible value of Void.

like image 192
Andy Turner Avatar answered Sep 28 '22 12:09

Andy Turner


They are alike except RecursiveTask returns a result while RecursiveAction has no return value.

like image 28
Yohannes Gebremariam Avatar answered Sep 28 '22 12:09

Yohannes Gebremariam