add 默认jdk提升到21 增加虚拟线程工具 简化业务

This commit is contained in:
疯狂的狮子Li
2026-03-19 10:17:54 +08:00
parent 261d00131e
commit e6eeb4f885
3 changed files with 49 additions and 11 deletions

View File

@@ -0,0 +1,36 @@
package org.dromara.common.core.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
/**
* 线程工具
*
* @author Lion Li
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ThreadUtils {
/**
* 批量执行任务
*/
public static void virtualSubmit(Runnable ...runnableList) {
List<Future<?>> callableList = new ArrayList<>();
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (Runnable runnable : runnableList) {
callableList.add(executor.submit(runnable));
}
for (Future<?> future : callableList) {
future.get();
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
}