-
-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathAsyncDispatcher.java
More file actions
37 lines (33 loc) · 1.12 KB
/
AsyncDispatcher.java
File metadata and controls
37 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.dreeam.leaf.async;
@org.jspecify.annotations.NullMarked
public final class AsyncDispatcher {
public static final ThreadPool INSTANCE;
static {
final String threadsProperty = System.getProperty("leaf.scheduler.threads");
int numThreads = Math.clamp(Runtime.getRuntime().availableProcessors() / 2, 1, 4);
if (threadsProperty != null) {
try {
int i = Integer.parseInt(threadsProperty);
if (i >= 1) {
numThreads = i;
}
} catch (NumberFormatException ignored) {
}
}
final String queueProperty = System.getProperty("leaf.scheduler.queue-size");
int queue = 8192;
if (queueProperty != null) {
try {
int j = Integer.parseInt(queueProperty);
if (j >= 1) queue = j;
} catch (NumberFormatException ignored) {
}
}
INSTANCE = new ThreadPool(numThreads,
queue,
"Leaf Async Scheduler",
Thread.NORM_PRIORITY - 1);
}
private AsyncDispatcher() {
}
}