Skip to content

Commit

Permalink
Use virtual threads rather than forkjoinpool
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 30, 2024
1 parent 11003e2 commit 4a5f6a3
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
* Used for most of the async tasks in the server, bots and plugins.
*/
public class SoulFireScheduler implements Executor {
private static final ForkJoinPool SF_FORK_JOIN_POOL = new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism(),
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
null, true);
private static final ScheduledExecutorService MANAGEMENT_SERVICE = Executors.newSingleThreadScheduledExecutor(Thread.ofVirtual()
.name("SoulFireScheduler-Management-", 0)
.factory());
private final ExecutorService executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual()
.name("SoulFireScheduler-Task-", 0)
.factory());
private final PriorityQueue<TimedRunnable> executionQueue = new ObjectHeapPriorityQueue<>();
private final Logger logger;
private final Function<Runnable, Runnable> runnableWrapper;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void schedule(Runnable command) {
return;
}

SF_FORK_JOIN_POOL.execute(() -> runCommand(command));
executor.execute(() -> runCommand(command));
}

public void schedule(Runnable command, long delay, TimeUnit unit) {
Expand Down

0 comments on commit 4a5f6a3

Please sign in to comment.