From 8c5bb96fdd39eb82d8288280fba2cdd1b7af3d0f Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Sat, 21 Oct 2023 17:48:35 +0200 Subject: [PATCH] Streamline fawe thread names (#2467) streamline fawe thread names --- .../bukkit/adapter/Regenerator.java | 13 ++++++------- .../main/java/com/fastasyncworldedit/core/Fawe.java | 2 +- .../java/com/fastasyncworldedit/core/FaweCache.java | 4 ++-- .../util/task/FaweForkJoinWorkerThreadFactory.java | 5 ++++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/Regenerator.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/Regenerator.java index d0d9bb652..607bc75bf 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/Regenerator.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/Regenerator.java @@ -41,6 +41,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; import java.util.function.Function; /** @@ -158,16 +159,14 @@ public abstract class Regenerator(), - new ThreadFactoryBuilder().setNameFormat("fawe-clipboard-%d").build() + new ThreadFactoryBuilder().setNameFormat("FAWE Clipboard - %d").build() )); } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java index af14624df..d8e1474e6 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java @@ -18,6 +18,7 @@ import com.fastasyncworldedit.core.util.collection.CleanableThreadLocal; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; @@ -48,7 +49,6 @@ import java.util.Map.Entry; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -616,7 +616,7 @@ public enum FaweCache implements Trimable { ArrayBlockingQueue queue = new ArrayBlockingQueue<>(nThreads, true); return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, queue, - Executors.defaultThreadFactory(), + new ThreadFactoryBuilder().setNameFormat("FAWE Blocking Executor - %d").build(), new ThreadPoolExecutor.CallerRunsPolicy() ) { diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/task/FaweForkJoinWorkerThreadFactory.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/task/FaweForkJoinWorkerThreadFactory.java index 589b5b863..2c8353ce8 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/task/FaweForkJoinWorkerThreadFactory.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/task/FaweForkJoinWorkerThreadFactory.java @@ -2,19 +2,22 @@ package com.fastasyncworldedit.core.util.task; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinWorkerThread; +import java.util.concurrent.atomic.AtomicInteger; public class FaweForkJoinWorkerThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory { private final String nameFormat; + private final AtomicInteger idCounter; public FaweForkJoinWorkerThreadFactory(String nameFormat) { this.nameFormat = nameFormat; + this.idCounter = new AtomicInteger(0); } @Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); - worker.setName(String.format(nameFormat, worker.getPoolIndex())); + worker.setName(String.format(nameFormat, idCounter.getAndIncrement())); return worker; }