| 87 | |
| 88 | // 固定数量的线程池, 普通优先级, 自动优先使用支持虚拟线程(不限制数量), 用于处理普通任务 |
| 89 | public static @NotNull ExecutorService newFixedThreadPool(int threadCount, @NotNull String threadNamePrefix) { |
| 90 | if (USE_UNLIMITED_VIRTUAL_THREAD && isVirtualThreadEnabled()) { |
| 91 | try { |
| 92 | var es = (ExecutorService)Executors.class.getMethod("newVirtualThreadPerTaskExecutor", |
| 93 | (Class<?>[])null).invoke(null, (Object[])null); |
| 94 | logger.info("newFixedThreadPool({},{}) use unlimited virtual thread pool", threadCount, threadNamePrefix); |
| 95 | return es; |
| 96 | } catch (ReflectiveOperationException ignored) { |
| 97 | } |
| 98 | } |
| 99 | return Executors.newFixedThreadPool(threadCount, |
| 100 | new ThreadFactoryWithName(threadNamePrefix, Thread.NORM_PRIORITY, USE_VIRTUAL_THREAD)); |
| 101 | } |
| 102 | |
| 103 | // 关键线程池, 不使用虚拟线程时设为普通优先级+2, 线程数按需增长, 用于处理关键任务, 比普通任务的处理更及时 |
| 104 | public static @NotNull ExecutorService newCriticalThreadPool(@NotNull String threadNamePrefix) { |