Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9227269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:01:50+00:00 2026-06-18T05:01:50+00:00

I found an example for fork/join in GPars here: Fork/Join import static groovyx.gpars.GParsPool.runForkJoin import

  • 0

I found an example for fork/join in GPars here: Fork/Join

import static groovyx.gpars.GParsPool.runForkJoin
import static groovyx.gpars.GParsPool.withPool
withPool() {
    println """Number of files: ${
        runForkJoin(new File("./src")) {file ->
            long count = 0
            file.eachFile {
                if (it.isDirectory()) {
                    println "Forking a child task for $it"
                    forkOffChild(it)           //fork a child task
                } else {
                    count++
                }
            }
            return count + (childrenResults.sum(0))
            //use results of children tasks to calculate and store own result
        }
    }"""
}

It works and returns the correct number of files, but unfortunately I don’t understand this line:

return count + (childrenResults.sum(0))

How exactly work count and childrenResult?
Why is a 0 passed as a parameter to sum()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:01:51+00:00Added an answer on June 18, 2026 at 5:01 am

    I’m not much familiar with GPars, but the link you provided says it is a Divide-and-Conquer algorithm and clarifies a bit more what’s implicit later on, explaining that forkOffChild() does not wait — instead getChildrenResults() does.

    You may find easier to understand the provided alternative approach in the same page, that uses a more Java-ish style, if you’re more familiar to that.

    childrenResults results in calling the method getChildrenResults(), this is the “join” in “Fork/Join”, it waits for all children to finish and then returns a list with the results of them (or re-throws any exception a children may have thrown).

    0 is just the initial value for the sum. If childrenResult is empty, that’s what gets summed to count:

    groovy:000> [].sum(1)
    ===> 1
    groovy:000> [1].sum(1)
    ===> 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found an example here to create a select list with optgroups using KnockoutJS.
How to get the text after the tag is found Example: #!/usr/bin/env python import
I found example of history.pushState() through stackoverflow but I don't understand what each thing
I found this example and used it How do you resize a Bitmap under
I found this example in the App Engine documentation . 1 <% 2 UserService
I found one example in which buttons are added to panels (instances of JPanel
I found an example for async ftp upload on msdn which does the following
I found an example in MSDN for string to datetime conversion. But it doesn't
I found an example of QueryPerformanceCounter, http://advancedcppwithexamples.blogspot.com/2009/08/measuring-elapsed-time-in-c-using_21.html The example measures a sleep of 100ms
I have found the example of using the local sockets . The code from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.