Skip to content

Commit

Permalink
Fixes #92 - Set name to sender threads.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Jun 14, 2021
1 parent 647ac86 commit 74fc07c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.LockSupport;
import java.util.function.Supplier;
Expand Down Expand Up @@ -115,6 +116,7 @@ public static Builder builder() {
return new Builder();
}

private final AtomicInteger threadIds = new AtomicInteger();
private final Config config;
private final CyclicBarrier barrier;
private ExecutorService executorService;
Expand Down Expand Up @@ -142,20 +144,25 @@ private CompletableFuture<Void> spawn() {

@Override
protected void doStart() throws Exception {
executorService = Executors.newCachedThreadPool();
executorService = Executors.newCachedThreadPool(this::newThread);
interrupted = false;
super.doStart();
}

private Thread newThread(Runnable job) {
return new Thread(job, String.format("%s@%x-sender-%d", getClass().getSimpleName(), hashCode(), threadIds.getAndIncrement()));
}

private void halt() {
LifeCycle.stop(this);
}

@Override
protected void doStop() throws Exception {
super.doStop();
interrupt();
executorService.shutdown();
threadIds.set(0);
super.doStop();
}

/**
Expand Down

0 comments on commit 74fc07c

Please sign in to comment.