mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 07:26:09 +00:00
Merge pull request #505 from HaHaWTH/master
Identify Moonrise worker threads correctly
This commit is contained in:
commit
748e027282
@ -31,6 +31,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@ -327,6 +329,28 @@ public abstract class AbstractPlatform implements Platform {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
private static final String moonrise = "Moonrise";
|
||||
public static int getMoonriseGenerationThreadsWithReflection() {
|
||||
try {
|
||||
Class<?> prioritisedThreadPoolClazz = Class.forName("ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool");
|
||||
Method getCoreThreadsMethod = prioritisedThreadPoolClazz.getDeclaredMethod("getCoreThreads");
|
||||
getCoreThreadsMethod.setAccessible(true);
|
||||
Class<?> moonriseCommonClazz = Class.forName("ca.spottedleaf.moonrise.common.util.MoonriseCommon");
|
||||
Object pool = moonriseCommonClazz.getDeclaredField("WORKER_POOL").get(null);
|
||||
int threads = ((Thread[]) getCoreThreadsMethod.invoke(pool)).length;
|
||||
logger.info("{} found, setting {} generation threads.", moonrise, threads);
|
||||
return threads;
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.info("{} not found.", moonrise);
|
||||
} catch (NoSuchMethodException | NoSuchFieldException e) {
|
||||
logger.warn("{} found, but field/method not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", moonrise);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
logger.error("Failed to access thread values in {}, assuming 1 generation thread.", moonrise, e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
|
@ -57,7 +57,7 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
private int generationThreads;
|
||||
|
||||
public PlatformImpl(TerraBukkitPlugin plugin) {
|
||||
generationThreads = getGenerationThreadsWithReflection("ca.spottedleaf.moonrise.common.util.MoonriseCommon", "WORKER_THREADS", "Moonrise");
|
||||
generationThreads = getMoonriseGenerationThreadsWithReflection();
|
||||
if (generationThreads == 0) {
|
||||
generationThreads = 1;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
public LifecyclePlatform() {
|
||||
generationThreads = getGenerationThreadsWithReflection("com.ishland.c2me.base.common.GlobalExecutors", "GLOBAL_EXECUTOR_PARALLELISM", "C2ME");
|
||||
if (generationThreads == 0) {
|
||||
generationThreads = getGenerationThreadsWithReflection("ca.spottedleaf.moonrise.common.util.MoonriseCommon", "WORKER_THREADS", "Moonrise");
|
||||
generationThreads = getMoonriseGenerationThreadsWithReflection();
|
||||
} if (generationThreads == 0) {
|
||||
generationThreads = 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user