ThrottlingChunkTaskDispatcher .java

net.minecraft.server.level.ThrottlingChunkTaskDispatcher (class, 48 lines): members: chunkPositionsInExecution, executorSchedulerName, getDebugStatus.

net.minecraft.server.levelclass48 linesserverextends ChunkTaskDispatcher1.7 KB

API Surface (3)

void onRelease(final long key)
void scheduleForExecution(final ChunkTaskPriorityQueue.TasksForChunk tasksForChunk)
String getDebugStatus()

Fields & Constants (3)

chunkPositionsInExecution
maxChunksInExecution
executorSchedulerName

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ThrottlingChunkTaskDispatcher.java48 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.level;
2
3
import com.google.common.annotations.VisibleForTesting;
4
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
5
import it.unimi.dsi.fastutil.longs.LongSet;
6
import java.util.concurrent.Executor;
7
import java.util.stream.Collectors;
8
import net.minecraft.util.thread.TaskScheduler;
9
import net.minecraft.world.level.ChunkPos;
10
import org.jspecify.annotations.Nullable;
11
12
public class ThrottlingChunkTaskDispatcher extends ChunkTaskDispatcher {
13
	private final LongSet chunkPositionsInExecution = new LongOpenHashSet();
14
	private final int maxChunksInExecution;
15
	private final String executorSchedulerName;
16
17
	public ThrottlingChunkTaskDispatcher(final TaskScheduler<Runnable> executor, final Executor dispatcherExecutor, final int maxChunksInExecution) {
18
		super(executor, dispatcherExecutor);
19
		this.maxChunksInExecution = maxChunksInExecution;
20
		this.executorSchedulerName = executor.name();
21
	}
22
23
	@Override
24
	protected void onRelease(final long key) {
25
		this.chunkPositionsInExecution.remove(key);
26
	}
27
28
	@Override
29
	protected ChunkTaskPriorityQueue.@Nullable TasksForChunk popTasks() {
30
		return this.chunkPositionsInExecution.size() < this.maxChunksInExecution ? super.popTasks() : null;
31
	}
32
33
	@Override
34
	protected void scheduleForExecution(final ChunkTaskPriorityQueue.TasksForChunk tasksForChunk) {
35
		this.chunkPositionsInExecution.add(tasksForChunk.chunkPos());
36
		super.scheduleForExecution(tasksForChunk);
37
	}
38
39
	@VisibleForTesting
40
	public String getDebugStatus() {
41
		return this.executorSchedulerName
42
			+ "=["
43
			+ this.chunkPositionsInExecution.longStream().mapToObj(key -> key + ":" + ChunkPos.unpack(key)).collect(Collectors.joining(","))
44
			+ "], s="
45
			+ this.sleeping;
46
	}
47
}
48

Decompiled Minecraft 26.3 source of ThrottlingChunkTaskDispatcher (net/minecraft/server/level/ThrottlingChunkTaskDispatcher.java) with Mojang official mappings, stored verbatim on the site.