Java Reference
In-Depth Information
Figure 7.4. The fork/join algorithm
Once again you can check the performance of the summing method explicitly using the fork/join
framework with the harness developed at the beginning of this chapter:
System.out.println("ForkJoin sum done in: " + measureSumPerf(
ForkJoinSumCalculator::forkJoinSum, 10_000_000) + " msecs" );
In this case it produces the following output:
ForkJoin sum done in: 41 msecs
Here, the performance is worse than the version using the parallel stream, but only because
you're obliged to put the whole stream of numbers into a long[] before being allowed to use it in
the ForkJoinSumCalculator task.
7.2.2. Best practices for using the fork/join framework
Even though the fork/join framework is relatively easy to use, unfortunately it's also easy to
misuse. Here are a few best practices to leverage it effectively:
 
Search WWH ::




Custom Search