Package groovy.concurrent
Class ConcurrentConfig
java.lang.Object
groovy.concurrent.ConcurrentConfig
Central configuration for Groovy's concurrent and parallel features.
Configuration is resolved in order:
- Programmatic overrides via setter methods
- System properties (
groovy.concurrent.poolsize,groovy.concurrent.virtual) - Sensible defaults (processors + 1, virtual threads on JDK 21+)
Inspired by GPars' GParsConfig and PoolUtils, modernised
for virtual threads and the Pool abstraction.
- Since:
- 6.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic intReturns the default parallelism level.static PoolReturns the global default pool.static booleanReturnstrueif virtual threads should be preferred.static voidsetDefaultParallelism(int size) Sets the default parallelism level programmatically.static voidsetDefaultPool(Pool pool) Sets the global default pool.
-
Method Details
-
getDefaultParallelism
public static int getDefaultParallelism()Returns the default parallelism level.Checks (in order): programmatic override, system property
groovy.concurrent.poolsize, thenRuntime.availableProcessors() + 1(following the GPars convention).- Returns:
- the default pool size, always > 0
-
setDefaultParallelism
public static void setDefaultParallelism(int size) Sets the default parallelism level programmatically. Pass0or a negative value to reset to the default.- Parameters:
size- the pool size, or ≤ 0 to reset
-
preferVirtualThreads
public static boolean preferVirtualThreads()Returnstrueif virtual threads should be preferred.Checks the system property
groovy.concurrent.virtual(default:trueon JDK 21+,falseotherwise).- Returns:
- whether to prefer virtual threads
-
getDefaultPool
Returns the global default pool. If none has been set, creates one based on current configuration: a virtual-thread pool ifpreferVirtualThreads()istrue, otherwise a fixed pool sized bygetDefaultParallelism().- Returns:
- the default pool, never
null
-
setDefaultPool
Sets the global default pool. Passnullto reset.- Parameters:
pool- the pool to use as default, ornullto reset
-