Package groovy.concurrent

# Class ConcurrentConfig

java.lang.Object
groovy.concurrent.ConcurrentConfig

public final class ConcurrentConfig extends Object
Central configuration for Groovy's concurrent and parallel features.

Configuration is resolved in order:

1. Programmatic overrides via setter methods
2. System properties (`groovy.concurrent.poolsize`, `groovy.concurrent.virtual`)
3. 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:
  - `Pool`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `getDefaultParallelism()`
  Returns the default parallelism level.
  `static Pool`
  `getDefaultPool()`
  Returns the global default pool.
  `static boolean`
  `preferVirtualThreads()`
  Returns `true` if virtual threads should be preferred.
  `static void`
  `setDefaultParallelism(int size)`
  Sets the default parallelism level programmatically.
  `static void`
  `setDefaultPool(Pool pool)`
  Sets the global default pool.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getDefaultParallelism

    public static int getDefaultParallelism()
    Returns the default parallelism level.

    Checks (in order): programmatic override, system property `groovy.concurrent.poolsize`, then `Runtime.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. Pass `0` or a negative value to reset to the default.
    Parameters:
      `size` - the pool size, or ≤ 0 to reset

  - ### preferVirtualThreads

    public static boolean preferVirtualThreads()
    Returns `true` if virtual threads should be preferred.

    Checks the system property `groovy.concurrent.virtual` (default: `true` on JDK 21+, `false` otherwise).

    Returns:
      whether to prefer virtual threads

  - ### getDefaultPool

    public static Pool getDefaultPool()
    Returns the global default pool. If none has been set, creates one based on current configuration: a virtual-thread pool if `preferVirtualThreads()` is `true`, otherwise a fixed pool sized by `getDefaultParallelism()`.
    Returns:
      the default pool, never `null`

  - ### setDefaultPool

    public static void setDefaultPool(Pool pool)
    Sets the global default pool. Pass `null` to reset.
    Parameters:
      `pool` - the pool to use as default, or `null` to reset