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. virtual() and io() use virtual threads when that executor can be created. Every worker is created with the pool it belongs to. current() uses that when the thread has no explicit binding, so a nested call sees the pool without rebinding on each element.
| 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 the pool carried by the current worker, 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 when virtual threads cannot be created. |
<T> |
public static T |
withCurrent(Pool pool, Supplier<T> supplier)Executes the supplier with the given pool as current. |
Creates a pool sized to availableProcessors(), backed by
ForkJoinPool. Ideal for CPU-bound work and parallel collections.
The parallelism cap matches fixed(int).
Returns the pool bound to the current scope, or the pool carried by
the current worker, or null. An explicit binding wins, including
a binding of null. A thread that is not one of this pool's
workers, including a common-pool worker, does not carry a pool.
Creates a fixed-size pool backed by ForkJoinPool for work-stealing and parallel stream isolation.
Parallelism is size and is a hard cap. Blocked workers are
not replaced, so CPU-bound work cannot raise the thread count.
A parallel-collection callback that blocks can stall the pool when
every worker blocks with a sibling still queued; leave one spare
thread, or use virtual() / io() for waiting work.
Creates a pool for I/O-bound work. Uses virtual threads when that executor can be created, otherwise a fixed pool sized by ConcurrentConfig.getDefaultParallelism.
Creates a virtual-thread-per-task pool, or a cached daemon pool when virtual threads cannot be created.