Limit the number of scheduler work threads

This commit is contained in:
Luck 2019-12-02 15:10:18 +00:00
parent 6fdd349654
commit 6325e25630
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 11 additions and 13 deletions

View File

@ -223,7 +223,7 @@ public class LegacyImporter implements Runnable {
private CommandResult result = CommandResult.FAILURE;
ImportCommand(CommandManager commandManager, int id, String command) {
super(commandManager.getPlugin());
super(commandManager.getPlugin(), Sender.IMPORT_UUID, Sender.IMPORT_NAME);
this.commandManager = commandManager;
this.id = id;
this.command = command;

View File

@ -69,7 +69,6 @@ public class BulkUpdateCommand extends SingleCommand {
}
if (args.size() == 2 && args.get(0).equalsIgnoreCase("confirm")) {
String id = args.get(1);
BulkUpdate operation = this.pendingOperations.asMap().remove(id);

View File

@ -32,6 +32,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -46,35 +47,37 @@ public abstract class AbstractJavaScheduler implements SchedulerAdapter {
.build()
);
private final ErrorReportingExecutor workerPool = new ErrorReportingExecutor(Executors.newCachedThreadPool(new ThreadFactoryBuilder()
private final ErrorReportingExecutor schedulerWorkerPool = new ErrorReportingExecutor(Executors.newCachedThreadPool(new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("luckperms-worker-%d")
.setNameFormat("luckperms-scheduler-worker-%d")
.build()
));
private final ForkJoinPool worker = new ForkJoinPool(32, ForkJoinPool.defaultForkJoinWorkerThreadFactory, (t, e) -> e.printStackTrace(), false);
@Override
public Executor async() {
return this.workerPool;
return this.worker;
}
@Override
public SchedulerTask asyncLater(Runnable task, long delay, TimeUnit unit) {
ScheduledFuture<?> future = this.scheduler.schedule(() -> this.workerPool.execute(task), delay, unit);
ScheduledFuture<?> future = this.scheduler.schedule(() -> this.schedulerWorkerPool.execute(task), delay, unit);
return () -> future.cancel(false);
}
@Override
public SchedulerTask asyncRepeating(Runnable task, long interval, TimeUnit unit) {
ScheduledFuture<?> future = this.scheduler.scheduleAtFixedRate(() -> this.workerPool.execute(task), interval, interval, unit);
ScheduledFuture<?> future = this.scheduler.scheduleAtFixedRate(() -> this.schedulerWorkerPool.execute(task), interval, interval, unit);
return () -> future.cancel(false);
}
@Override
public void shutdown() {
this.scheduler.shutdown();
this.workerPool.delegate.shutdown();
this.schedulerWorkerPool.delegate.shutdown();
try {
this.workerPool.delegate.awaitTermination(1, TimeUnit.MINUTES);
this.schedulerWorkerPool.delegate.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -45,10 +45,6 @@ public abstract class DummySender implements Sender {
this.name = name;
}
public DummySender(LuckPermsPlugin plugin) {
this(plugin, Sender.IMPORT_UUID, Sender.IMPORT_NAME);
}
protected abstract void consumeMessage(String s);
@Override