Skip to content

Commit

Permalink
Use internal Dispatcher thread factory to launch Dispatcher threads (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored Sep 21, 2024
1 parent 1089d72 commit de8b593
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/com/pivovarit/collectors/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,8 @@ final class Dispatcher<T> {
private final CompletableFuture<Void> completionSignaller = new CompletableFuture<>();
private final BlockingQueue<Runnable> workingQueue = new LinkedBlockingQueue<>();

private final ThreadFactory dispatcherThreadFactory = Thread::startVirtualThread;

private final Executor executor;
private final Semaphore limiter;

Expand Down Expand Up @@ -72,7 +75,7 @@ static <T> Dispatcher<T> virtual(int permits) {

void start() {
if (!started.getAndSet(true)) {
Thread.startVirtualThread(() -> {
dispatcherThreadFactory.newThread(() -> {
try {
while (true) {
try {
Expand Down

0 comments on commit de8b593

Please sign in to comment.