add 增加 StringUtils.isVirtual 方法

update 优化 undertow 虚拟线程实现
This commit is contained in:
疯狂的狮子Li
2024-01-12 17:27:40 +08:00
parent 7f64fa7037
commit d4f8b93fe3
3 changed files with 16 additions and 10 deletions

View File

@@ -3,7 +3,9 @@ package org.dromara.common.core.utils;
import cn.hutool.extra.spring.SpringUtil;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.thread.Threading;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
@@ -59,4 +61,8 @@ public final class SpringUtils extends SpringUtil {
return getApplicationContext();
}
public static boolean isVirtual() {
return Threading.VIRTUAL.isActive(getBean(Environment.class));
}
}

View File

@@ -25,8 +25,10 @@ public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServle
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 512));
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
// 使用虚拟线程 解除下方注释 仅限jdk21
// if (SpringUtils.getProperty("spring.threads.virtual.enabled", Boolean.class, false)) {
// deploymentInfo.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
// if (SpringUtils.isVirtual()) {
// ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
// deploymentInfo.setExecutor(executor);
// deploymentInfo.setAsyncExecutor(executor);
// }
});
}