What is the GPars default pool size?
Asked Answered
E

2

9

I thought this would have been an easy thing to find but I've failed.

If I use GPars in my Groovy application and I don't specify a pool size how many threads will be created? Is there a default pool size without setting one?

// How many threads will be created? What is the default pool size?
GParsExecutorsPool.withPool {
    // do stuff...
}
Expensive answered 12/1, 2012 at 17:3 Comment(0)
S
18

It is (by default) set to

private static int defaultPoolSize() {
  return Runtime.getRuntime().availableProcessors() + 1;
}

You can alter this (I believe) by setting a System property called gpars.poolsize to a valid Integer

Sosthenna answered 12/1, 2012 at 17:13 Comment(1)
Why is it "availableProcessors" plus one? I'd expect it to be minus one, to leave one available for other systems? (unless of course you only have one to begin with!)Kent
R
8

As many as you have CPU units plus one, as shown by the PoolUtils class source, or from a system property

retrieveDefaultPoolSize() is called once as a final static variable by the GParsPool class when it's initialized

Roseola answered 12/1, 2012 at 17:13 Comment(1)
Thanks, upvoted you for the source link. But had to give tim_yates the answer for being first :-)Expensive

© 2022 - 2024 — McMap. All rights reserved.