MCPcopy Create free account
hub / github.com/e2wugui/zeze / Task

Class Task

ZezeJava/ZezeJava/src/main/java/Zeze/Util/Task.java:30–1134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28import org.jetbrains.annotations.Nullable;
29
30public final class Task {
31 // 通常不建议开,事务并发量太大时并发冲突可能很高导致频繁redo
32 private static final boolean USE_VIRTUAL_THREAD = PropertiesHelper.getBool("useVirtualThread", true);
33 private static final boolean USE_UNLIMITED_VIRTUAL_THREAD = USE_VIRTUAL_THREAD
34 && PropertiesHelper.getBool("useUnlimitedVirtualThread", !inJUnitTest());
35
36 // 默认不开启热更,这个实现希望能被优化掉,几乎不造成影响。
37 // 开启热更时,由App.HotManager初始化的时候设置。
38 @SuppressWarnings("CanBeFinal")
39 public static volatile @NotNull Factory<HotGuard> hotGuard = () -> null;
40 private static final FastLock taskLock = new FastLock();
41 private static final TaskOneByOneByKey oneByOne = new TaskOneByOneByKey();
42
43 @FunctionalInterface
44 public interface ILogAction {
45 void run(@Nullable Throwable ex, long result, @Nullable Protocol<?> p, @NotNull String actionName);
46 }
47
48 @SuppressWarnings("CanBeFinal")
49 public static volatile long defaultTimeout = 120_000; // 2 minutes
50
51 static final @NotNull Logger logger = LogManager.getLogger(Task.class);
52 private static ExecutorService threadPoolDefault;
53 private static ScheduledExecutorService threadPoolScheduled;
54 private static ExecutorService threadPoolCritical; // 用来执行内部的一些重要任务,和系统默认 ThreadPool 分开,防止饥饿。
55 // private static final ThreadPoolExecutor rpcResponseThreadPool
56 // = (ThreadPoolExecutor)Executors.newCachedThreadPool(new ThreadFactoryWithName("ZezeRespPool"));
57 @SuppressWarnings("CanBeFinal")
58 public static @Nullable ILogAction logAction = Task::DefaultLogAction;
59
60 static {
61 ShutdownHook.init();
62 }
63
64 public static boolean isVirtualThreadEnabled() {
65 return ThreadFactoryWithName.isVirtualThreadEnabled();
66 }
67
68 public static boolean inJUnitTest() {
69 return System.getProperty("sun.java.command").split(" ")[0].endsWith(".JUnitStarter");
70 }
71
72 public static @NotNull TaskOneByOneByKey getOneByOne() {
73 return oneByOne;
74 }
75
76 public static ExecutorService getThreadPool() {
77 return threadPoolDefault;
78 }
79
80 public static ScheduledExecutorService getScheduledThreadPool() {
81 return threadPoolScheduled;
82 }
83
84 public static @NotNull ExecutorService getCriticalThreadPool() {
85 return threadPoolCritical;
86 }
87

Callers

nothing calls this directly

Calls 3

getBoolMethod · 0.95
inJUnitTestMethod · 0.95
initMethod · 0.95

Tested by

no test coverage detected