Skip to content

Commit

Permalink
Revert "misc: 使用ThreadPoolExecutor根据情况动态调整查询线程数量"
Browse files Browse the repository at this point in the history
This reverts commit 4c02da6.
  • Loading branch information
MATRIX-feather committed Oct 14, 2024
1 parent 74f0850 commit 4a6c859
Showing 1 changed file with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,40 @@ public static ExecutorService executor()

MorphPlugin.getInstance()
.getSLF4JLogger()
.info("Creating new executor with a maximum of " + getMaximumThreadCount() + " thread(s) for profile lookup.");
.info("Creating new executor with a maximum of " + getThreadCount() + " thread(s) for profile lookup.");
}

return executor;
}

private static int getMaximumThreadCount()
private static int getThreadCount()
{
return Math.min(16, Math.max(4, Runtime.getRuntime().availableProcessors() / 2));
return Math.max(4, Runtime.getRuntime().availableProcessors() / 2);
}

private static ExecutorService createExecutor()
{
return new ThreadPoolExecutor(1, getMaximumThreadCount(),
10, TimeUnit.MINUTES,
new SynchronousQueue<>(),
new ThreadFactory()
return Executors.newFixedThreadPool(getThreadCount(), new ThreadFactory()
{
private final AtomicInteger threadCount = new AtomicInteger(0);

@Override
public Thread newThread(@NotNull Runnable runnable)
{
Thread thread = new Thread(runnable);
var threadId = this.threadCount.getAndIncrement();
thread.setName("FeatherMorph Profile Executor #" + threadId);

thread.setUncaughtExceptionHandler((Thread t, Throwable error) ->
{
private final AtomicInteger threadCount = new AtomicInteger(0);

@Override
public Thread newThread(@NotNull Runnable runnable)
{
Thread thread = new Thread(runnable);
var threadId = this.threadCount.getAndIncrement();
thread.setName("FeatherMorph Profile Executor #" + threadId);

thread.setUncaughtExceptionHandler((Thread t, Throwable error) ->
{
MorphPlugin.getInstance()
.getSLF4JLogger()
.error("Error occurred in thread " + t.getName(), error);
});

return thread;
}
MorphPlugin.getInstance()
.getSLF4JLogger()
.error("Error occurred in thread " + t.getName(), error);
});

return thread;
}
});
}

@Nullable
Expand Down

0 comments on commit 4a6c859

Please sign in to comment.