Improve ThreadUtil logging and prefix handling
This commit is contained in:
+2
-2
@@ -34,6 +34,8 @@ public class WorldGenerationQueue implements Closeable, IDebugRenderable
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
public static final DhThreadFactory THREAD_FACTORY = new DhThreadFactory(ThreadUtil.THREAD_NAME_PREFIX + "Gen-Worker-Thread", Thread.MIN_PRIORITY);
|
||||
|
||||
private final IDhApiWorldGenerator generator;
|
||||
|
||||
/** contains the positions that need to be generated */
|
||||
@@ -497,8 +499,6 @@ public class WorldGenerationQueue implements Closeable, IDebugRenderable
|
||||
// executor handler methods //
|
||||
//==========================//
|
||||
|
||||
public static final DhThreadFactory THREAD_FACTORY = new DhThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY);
|
||||
|
||||
/**
|
||||
* Creates a new executor. <br>
|
||||
* Does nothing if an executor already exists.
|
||||
|
||||
@@ -4,11 +4,18 @@ import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener;
|
||||
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||
import com.seibel.distanthorizons.core.util.objects.DhThreadFactory;
|
||||
import com.seibel.distanthorizons.core.util.objects.RateLimitedThreadPoolExecutor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class ThreadUtil
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/** The prefix isn't strictly required, but makes debugging and profiling much easier. */
|
||||
public static String THREAD_NAME_PREFIX = "DH-";
|
||||
|
||||
public static int MINIMUM_RELATIVE_PRIORITY = -4;
|
||||
public static int DEFAULT_RELATIVE_PRIORITY = 0;
|
||||
|
||||
@@ -26,7 +33,7 @@ public class ThreadUtil
|
||||
}
|
||||
public static RateLimitedThreadPoolExecutor makeRateLimitedThreadPool(int poolSize, String name, int relativePriority, ConfigEntry<Double> runTimeRatioConfigEntry)
|
||||
{
|
||||
DhThreadFactory threadFactory = new DhThreadFactory("DH-" + name, Thread.NORM_PRIORITY + relativePriority);
|
||||
DhThreadFactory threadFactory = new DhThreadFactory(THREAD_NAME_PREFIX + name, Thread.NORM_PRIORITY + relativePriority);
|
||||
return makeRateLimitedThreadPool(poolSize, threadFactory, runTimeRatioConfigEntry);
|
||||
}
|
||||
public static RateLimitedThreadPoolExecutor makeRateLimitedThreadPool(int poolSize, DhThreadFactory threadFactory, ConfigEntry<Double> runTimeRatioConfigEntry)
|
||||
@@ -39,6 +46,12 @@ public class ThreadUtil
|
||||
THREAD_CHANGE_LISTENERS_BY_THREAD_NAME.remove(threadFactory.threadName);
|
||||
}
|
||||
|
||||
if (!threadFactory.threadName.startsWith(THREAD_NAME_PREFIX))
|
||||
{
|
||||
// this will only happen if a ThreadFactory is passed in that doesn't have the correct thread name
|
||||
LOGGER.warn("Thread pool with the name ["+threadFactory.threadName+"] is missing the expected Distant Horizons thread prefix ["+THREAD_NAME_PREFIX+"].");
|
||||
}
|
||||
|
||||
|
||||
RateLimitedThreadPoolExecutor executor = makeRateLimitedThreadPool(poolSize, runTimeRatioConfigEntry.get(), threadFactory);
|
||||
|
||||
@@ -52,7 +65,7 @@ public class ThreadUtil
|
||||
/** should only be used if there isn't a config controlling the run time ratio of this thread pool */
|
||||
public static RateLimitedThreadPoolExecutor makeRateLimitedThreadPool(int poolSize, String name, Double runTimeRatio, int relativePriority)
|
||||
{
|
||||
return new RateLimitedThreadPoolExecutor(poolSize, runTimeRatio, new DhThreadFactory("DH-" + name, Thread.NORM_PRIORITY + relativePriority));
|
||||
return new RateLimitedThreadPoolExecutor(poolSize, runTimeRatio, new DhThreadFactory(THREAD_NAME_PREFIX + name, Thread.NORM_PRIORITY + relativePriority));
|
||||
}
|
||||
public static RateLimitedThreadPoolExecutor makeRateLimitedThreadPool(int poolSize, Double runTimeRatio, DhThreadFactory threadFactory)
|
||||
{
|
||||
@@ -70,7 +83,7 @@ public class ThreadUtil
|
||||
return new ThreadPoolExecutor(/*corePoolSize*/ poolSize, /*maxPoolSize*/ poolSize,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(),
|
||||
new DhThreadFactory("DH-" + name, Thread.NORM_PRIORITY + relativePriority));
|
||||
new DhThreadFactory(THREAD_NAME_PREFIX + name, Thread.NORM_PRIORITY + relativePriority));
|
||||
}
|
||||
|
||||
public static ThreadPoolExecutor makeThreadPool(int poolSize, Class<?> clazz, int relativePriority) { return makeThreadPool(poolSize, clazz.getSimpleName(), relativePriority); }
|
||||
|
||||
Reference in New Issue
Block a user