Hello Campers!
Please let me start off by wishing my fellow Java-heads a very happy Towel Day!
Now, to get straight to the biscuits...
I am reading the interesting and helpful book, "
Oracle Certified Professional Java SE 7 Programmer Exams 1Z0-804 and 1Z0-805 - A Comprehensive OCPJP7 Certification Guide" by Ganesh and Sharma (2013). In this book there is an interesting program that illustrates how to use some classes from the java.util.concurrent.*; package. One I am trying to understand with my limited bonobos brain has to do with the "fork/join framework". I modified the code located in the Ganesh and Sharma (2013) book, referenced above, so that I could understand what the program was doing.
My question is: What is the fork() method doing in the program? Is it recursively calling the compute() method or is it summing up the numbers without making sure the value is not too large in the first if statement in the compute() method. That if statement is: if ( (to - from) <= N/NUM_THREADS)
The full program is below. I made some formatting modifications to display number values using the US locale and also to print some more debugging information such as count and note every time compute() is called. I also count every time fork() is called and then print out the totals upon program completion to verify that in fact every time fork() is called, compute() is again called from itself as a recursive method invocation.
The Code:
Thank-you for reading this post, especially on
Hitchhiker's Guide to the Galaxy Day!
Respectfully,
Tedster