feature #ICUMKV 全面支持jdk21,以及支持jdk21中的虚拟线程

This commit is contained in:
everywhere.z
2025-08-27 14:33:27 +08:00
parent 4f63f7d3d2
commit 269bc22ea5
4 changed files with 25 additions and 10 deletions

View File

@@ -570,13 +570,18 @@ public class Node implements Executable, Cloneable, Rollbackable{
if (parentValue == null) {
return null;
}
// 克隆 Stack
return (Stack<TupleOf2<Integer, Integer>>) parentValue.clone();
Stack<TupleOf2<Integer, Integer>> newStack = new Stack<>();
for (TupleOf2<Integer, Integer> tuple : parentValue) {
newStack.push(new TupleOf2<>(tuple.getA(), tuple.getB()));
}
return newStack;
}
};
node.loopObjectTL = new TransmittableThreadLocal<Stack<TupleOf2<Integer, Object>>>() {
/**
* 在你提供的这个 TTL 版本中,我们重写 public T copy(T parentValue) 方法
* 我们重写 public T copy(T parentValue) 方法
* 来实现 Stack 的克隆,以确保线程隔离。
*/
@Override
@@ -585,8 +590,13 @@ public class Node implements Executable, Cloneable, Rollbackable{
if (parentValue == null) {
return null;
}
// 克隆 Stack
return (Stack<TupleOf2<Integer, Object>>) parentValue.clone();
Stack<TupleOf2<Integer, Object>> newStack = new Stack<>();
for (TupleOf2<Integer, Object> tuple : parentValue) {
newStack.push(new TupleOf2<>(tuple.getA(), tuple.getB()));
}
return newStack;
}
};
node.accessResult = new TransmittableThreadLocal<>();

View File

@@ -125,12 +125,12 @@ public class Slot {
}
private <T> void putThreadMetaDataMap(String key, T t) {
String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getName());
String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getId());
putMetaDataMap(threadKey, t);
}
private <T> T getThreadMetaData(String key) {
String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getName());
String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getId());
return (T) metaDataMap.get(threadKey);
}

View File

@@ -24,7 +24,7 @@ public interface ExecutorBuilder {
if (ExecutorHelper.loadInstance().isEnabledVirtualThreads()){
Method method = ReflectUtil.getMethodByName(Executors.class, "newVirtualThreadPerTaskExecutor");
executorService = ReflectUtil.invokeStatic(method);
executorService = TtlExecutors.getTtlExecutorService(ReflectUtil.invokeStatic(method));
}else{
executorService = TtlExecutors.getTtlExecutorService(new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 60,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(queueCapacity), new ThreadFactory() {

View File

@@ -216,9 +216,14 @@ public class ExecutorHelper {
return executor;
}
private Boolean isEnabledVirtualThreadsCache;
public boolean isEnabledVirtualThreads(){
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
return BooleanUtil.isTrue(liteflowConfig.getEnableVirtualThread() && JdkUtil.JVM_VERSION == 21);
if (isEnabledVirtualThreadsCache == null){
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
isEnabledVirtualThreadsCache = BooleanUtil.isTrue(liteflowConfig.getEnableVirtualThread() && JdkUtil.JVM_VERSION == 21);
}
return isEnabledVirtualThreadsCache;
}
}