Skip to content

Commit

Permalink
fix: don't use NEXT_WORKER_ID in Util mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo committed Dec 12, 2023
1 parent d829f38 commit acdf24b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/github/getchoo/smoothboot/mixin/UtilMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public abstract class UtilMixin {

@Shadow @Final @Mutable
private static ExecutorService IO_WORKER_EXECUTOR;

@Shadow @Final
private static AtomicInteger NEXT_WORKER_ID;


@Shadow
private static void uncaughtExceptionHandler(Thread thread, Throwable throwable) {}

Expand Down Expand Up @@ -73,9 +70,11 @@ private static ExecutorService replWorker(String name) {
SmoothBoot.initConfig = true;
}

AtomicInteger atomicInteger = new AtomicInteger(1);

return new ForkJoinPool(MathHelper.clamp(select(name, SmoothBoot.config.threadCount.bootstrap,
SmoothBoot.config.threadCount.main), 1, 0x7fff), (forkJoinPool) -> {
String workerName = "Worker-" + name + "-" + NEXT_WORKER_ID.getAndIncrement();
String workerName = "Worker-" + name + "-" + atomicInteger.getAndIncrement();
SmoothBoot.LOGGER.debug("Initialized " + workerName);

ForkJoinWorkerThread forkJoinWorkerThread = new LoggingForkJoinWorkerThread(forkJoinPool, SmoothBoot.LOGGER);
Expand All @@ -90,8 +89,10 @@ private static ExecutorService replWorker(String name) {
* Replace
*/
private static ExecutorService replIoWorker() {
AtomicInteger atomicInteger = new AtomicInteger(1);

return Executors.newCachedThreadPool((runnable) -> {
String workerName = "IO-Worker-" + NEXT_WORKER_ID.getAndIncrement();
String workerName = "IO-Worker-" + atomicInteger.getAndIncrement();
SmoothBoot.LOGGER.debug("Initialized " + workerName);

Thread thread = new Thread(runnable);
Expand Down

0 comments on commit acdf24b

Please sign in to comment.