Java multithreading recursion in our use when we need to continue to learn, in fact, each language can be found in the source code to solve the problem. This sequential cycle is appropriate for parallelization when each iteration is independent of each other and completes the work of each iteration of Java multithreaded recursion, which is significant enough to compensate for the overhead of managing a new task.
1.public voidparallelrecursive (final executorexec,
List
2.for (Node n:nodes) {
3.exec.execute (New Runnable () {
4.public void Run () {
5.results.add (N.compute ());
6.}
7.});
8.parallelRecursive (Exec,n.getchildren (), results);
9.}
10.}
11.public Collection getparallelresults (List
12.throws interruptedexception{
13.ExecutorService Exec=executors.newcachedthreadpool ();
14.Queue resultqueue=newconcurrentlinkedqueue ();
15.parallelRecursive (Exec,nodes,resultqueue);
16.exec.shutdown ();
17.exec.awaittermination (Long.max_value,timeunit.seconds);
18.return Reslutqueue;
19.}
However, Java multithreaded recursive programs cannot handle situations where there are no scenarios, and the following programs can solve the problem.