Skip to content

Commit 6d28323

Browse files
committed
Virtual thread for ChunkIO
1 parent e053f99 commit 6d28323

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: HaHaWTH <id_cn00@outlook.com>
3+
Date: Wed, 1 May 2024 02:53:15 +0800
4+
Subject: [PATCH] virtual-thread-for-chunkio
5+
6+
7+
diff --git a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
8+
index cf1258c559ce47bfb0f3dbd94302eacfd5fc08a0..80313bfaaca8b2e1fd3c4eaa86ebe49742b09747 100644
9+
--- a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
10+
+++ b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
11+
@@ -217,7 +217,7 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
12+
final CallBackProvider<P, T, C, E> provider;
13+
final Queue<Task> finished = new ConcurrentLinkedQueue<Task>();
14+
final Map<P, Task> tasks = new HashMap<P, Task>();
15+
- final ThreadPoolExecutor pool;
16+
+ ThreadPoolExecutor pool;
17+
18+
/**
19+
* Uses a thread pool to pass executions to the provider.
20+
@@ -226,7 +226,17 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
21+
public AsynchronousExecutor(final CallBackProvider<P, T, C, E> provider, final int coreSize) {
22+
Validate.notNull(provider, "Provider cannot be null");
23+
this.provider = provider;
24+
-
25+
+ // Beast start - Virtual Threads for async executor
26+
+ if (com.homomc.beast.virtualthreads.VirtualThreadService.getJavaMajorVersion() >= com.homomc.beast.virtualthreads.VirtualThreadService.minimumJavaMajorVersionWithoutFeaturePreview && com.homomc.beast.BeastConfig.virtualThreadForAsyncExecutor) {
27+
+ try {
28+
+ pool = new ThreadPoolExecutor(coreSize, Integer.MAX_VALUE, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), provider);
29+
+ pool.setThreadFactory(com.homomc.beast.virtualthreads.VirtualThreadService.get().createFactory());
30+
+ return;
31+
+ } catch (Exception e) {
32+
+ System.err.println("Failed to create Virtual Thread executor! Fallback to default executor.");
33+
+ }
34+
+ }
35+
+ // Beast end
36+
// We have an unbound queue size so do not need a max thread size
37+
pool = new ThreadPoolExecutor(coreSize, Integer.MAX_VALUE, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), provider);
38+
}

0 commit comments

Comments
 (0)