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

  • Home
  • SEARCH
  • 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 9159825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:35:17+00:00 2026-06-17T13:35:17+00:00

I found an example on how to use withPool . It says I just

  • 0

I found an example on how to use withPool. It says I just need to add the word Parallel to Groovy’s methods like collect, find, each, put it into withPool and it executes the code parallel.

import static groovyx.gpars.GParsPool.withPool

list = 1..1000000

withPool{
    squares = list.collectParallel { it * it}
}
println squares

Is there any chance to check if it’s really parallel?
I tried a benchmark test with the same code but the sequential way
and the parallel way was much more slowly.

  • 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-17T13:35:18+00:00Added an answer on June 17, 2026 at 1:35 pm

    Not sure what you mean by ‘but sequential and the parallel way was much more slowly’…

    This will run in parallel, but for this simplistic example, the extra cost of firing off jobs to other processors and handling the ordering of results will probably end up taking longer than just multiplying some numbers

    For a simplistic example showing it working, you can do:

    import static groovyx.gpars.GParsPool.withPool
    
    list = [ 2, 2, 2, 2, 2 ]
    
    withPool{
        result = list.collectParallel {
            Thread.sleep( it * 1000 )
            it
        }
    }
    println result
    

    So result should be [2,2,2,2,2], but the collectParallel should finish in less than the 10 seconds you’d expect with the serial collect version

    Obviously this depends on you having more than one core 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use ExpandableList in my app. I found this example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html which
I just started programming in Objective-C and found some example comments like the following:
I found that most tutorials use one big router. For example: https://github.com/thomasdavis/backboneboilerplate/blob/gh-pages/js/router.js Wouldn't it
At http://www.java2s.com/Code/Java/EJB3/EJBtutorialfromJBossAsynchronouscall.htm i've found an example showing how to call ejb methods in asynchronous
I can't found some example how can I use argument -a when I use
I found an example called nativeactivity in FMOD example folder, but unfortunately it use
I want use UIImagePickerController, and I found this example Added to .h @interface MenuScene
I'm trying to use the example found in: example , and I can get
I have modified the example found here to use two io channels. None of
I'd like to know the requirements to use CouchDB on Android . I've found

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.