Skip to content

Commit

Permalink
Added a max thread count
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixuge committed Jun 29, 2023
1 parent b7a6067 commit 22fe6b0
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ public class ServerListEntryNormalMixin {

@Shadow
private static ThreadPoolExecutor field_148302_b;

private static final int MAX_THREAD_COUNT_PINGER = 50;
private static final int MAX_THREAD_COUNT_TIMEOUT = 100;

// Note: if servers are added, this will be inaccurate
// But it should be good enough still
// Can't bother to mixin onto some other classes just to change that (rn at least).
private static final int serverCountCache;
static {
serverCountCache = new ServerList(Minecraft.getMinecraft()).countServers();
// Note: not even sure this reassignement works since the field is final
field_148302_b = new ScheduledThreadPoolExecutor(serverCountCache + 5, (new ThreadFactoryBuilder()).setNameFormat("Server Pinger #%d").setDaemon(true).build());
field_148302_b = new ScheduledThreadPoolExecutor(Math.min(serverCountCache + 5, MAX_THREAD_COUNT_PINGER), (new ThreadFactoryBuilder()).setNameFormat("Server Pinger #%d").setDaemon(true).build());
}
private final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(serverCountCache * 2 + 5);
private final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(Math.min(serverCountCache + 5, MAX_THREAD_COUNT_TIMEOUT));

private static int runningTaskCount = 0;

Expand Down

0 comments on commit 22fe6b0

Please # to comment.