TracingExecutor .java

net.minecraft.TracingExecutor (record): members: service, shutdownAndAwait, wrapUnnamed, forName, execute. strings: "task". imports: Zone, TracyClient.

net.minecraftrecord60 linescommon1.6 KB

Implements

API Surface (3)

Executor forName(final String name)
void execute(final Runnable command)
void shutdownAndAwait(final long timeout, final TimeUnit unit)

String literals (1)

"task"

Code Graph: Dependencies (1)

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

Full Source

TracingExecutor.java60 lines · Minecraft 26.3 · verbatim
1
package net.minecraft;
2
3
import com.mojang.jtracy.TracyClient;
4
import com.mojang.jtracy.Zone;
5
import java.util.concurrent.Executor;
6
import java.util.concurrent.ExecutorService;
7
import java.util.concurrent.TimeUnit;
8
9
public record TracingExecutor(ExecutorService service) implements Executor {
10
	public Executor forName(final String name) {
11
		if (SharedConstants.IS_RUNNING_IN_IDE) {
12
			return command -> this.service.execute(() -> {
13
				Thread thread = Thread.currentThread();
14
				String oldName = thread.getName();
15
				thread.setName(name);
16
17
				try (Zone ignored = TracyClient.beginZone(name, SharedConstants.IS_RUNNING_IN_IDE)) {
18
					command.run();
19
				} finally {
20
					thread.setName(oldName);
21
				}
22
			});
23
		} else {
24
			return TracyClient.isAvailable() ? command -> this.service.execute(() -> {
25
				try (Zone ignored = TracyClient.beginZone(name, SharedConstants.IS_RUNNING_IN_IDE)) {
26
					command.run();
27
				}
28
			}) : this.service;
29
		}
30
	}
31
32
	@Override
33
	public void execute(final Runnable command) {
34
		this.service.execute(wrapUnnamed(command));
35
	}
36
37
	public void shutdownAndAwait(final long timeout, final TimeUnit unit) {
38
		this.service.shutdown();
39
40
		boolean terminated;
41
		try {
42
			terminated = this.service.awaitTermination(timeout, unit);
43
		} catch (InterruptedException e) {
44
			terminated = false;
45
		}
46
47
		if (!terminated) {
48
			this.service.shutdownNow();
49
		}
50
	}
51
52
	private static Runnable wrapUnnamed(final Runnable command) {
53
		return !TracyClient.isAvailable() ? command : () -> {
54
			try (Zone ignored = TracyClient.beginZone("task", SharedConstants.IS_RUNNING_IN_IDE)) {
55
				command.run();
56
			}
57
		};
58
	}
59
}
60

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