diff --git a/src/main/java/com/pivovarit/collectors/Dispatcher.java b/src/main/java/com/pivovarit/collectors/Dispatcher.java index 910a9cb2..b9ff37ff 100644 --- a/src/main/java/com/pivovarit/collectors/Dispatcher.java +++ b/src/main/java/com/pivovarit/collectors/Dispatcher.java @@ -9,6 +9,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.Semaphore; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.function.Supplier; @@ -25,6 +26,8 @@ final class Dispatcher { private final CompletableFuture completionSignaller = new CompletableFuture<>(); private final BlockingQueue workingQueue = new LinkedBlockingQueue<>(); + private final ThreadFactory dispatcherThreadFactory = Thread::startVirtualThread; + private final Executor executor; private final Semaphore limiter; @@ -72,7 +75,7 @@ static Dispatcher virtual(int permits) { void start() { if (!started.getAndSet(true)) { - Thread.startVirtualThread(() -> { + dispatcherThreadFactory.newThread(() -> { try { while (true) { try {