Package: org.apache.groovy.runtime.async

## [Java] Class DefaultPool

- org.apache.groovy.runtime.async.DefaultPool

- All Implemented Interfaces and Traits:
    Pool

      public final class DefaultPool
      extends Object
      implements Pool

  Default implementation of Pool.

  Sized pools (fixed(int), cpu()) use ForkJoinPool for work-stealing and parallel stream isolation. I/O pools (virtual(), io()) use virtual threads on JDK 21+.

  See Also:
    Pool
  Since:
    6.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public ForkJoinPool` | `asForkJoinPool()`
    `` | `public static Pool` | `cpu()` Creates a pool sized to `availableProcessors()`, backed by ForkJoinPool.
    `` | `public static Pool` | `current()` Returns the pool bound to the current scope, or `null`.
    `` | `public void` | `execute(Runnable command)`
    `` | `public static Pool` | `fixed(int size)` Creates a fixed-size pool backed by ForkJoinPool for work-stealing and parallel stream isolation.
    `` | `public int` | `getActiveCount()`
    `` | `public int` | `getPoolSize()`
    `` | `public static Pool` | `io()` Creates a pool for I/O-bound work.
    `` | `public void` | `shutdown()`
    `` | `public String` | `toString()`
    `` | `public boolean` | `usesVirtualThreads()`
    `` | `public static Pool` | `virtual()` Creates a virtual-thread-per-task pool, or a cached daemon pool as fallback on JDK < 21.
    `<T>` | `public static T` | `withCurrent(Pool pool, Supplier<T> supplier)` Executes the supplier with the given pool as current.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public ForkJoinPool asForkJoinPool()

    - #### public static Pool cpu()

      Creates a pool sized to `availableProcessors()`, backed by ForkJoinPool. Ideal for CPU-bound work and parallel collections.

    - #### public static Pool current()

      Returns the pool bound to the current scope, or `null`.

    - #### public void execute(Runnable command)

    - #### public static Pool fixed(int size)

      Creates a fixed-size pool backed by ForkJoinPool for work-stealing and parallel stream isolation.

    - #### public int getActiveCount()

    - #### public int getPoolSize()

    - #### public static Pool io()

      Creates a pool for I/O-bound work. Uses virtual threads if available, otherwise a fixed pool sized by ConcurrentConfig.getDefaultParallelism.

    - #### public void shutdown()

    - #### public String toString()

    - #### public boolean usesVirtualThreads()

    - #### public static Pool virtual()

      Creates a virtual-thread-per-task pool, or a cached daemon pool as fallback on JDK < 21.

    - #### <T> public static T withCurrent(Pool pool, Supplier<T> supplier)

      Executes the supplier with the given pool as current.