修改编译参数
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
添加配置类
package com.example.virtualthreadsdemo.config;
import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.Executors;
@Configuration
public class VirtualThreadsConfig {
@Bean
AsyncTaskExecutor applicationTaskExecutor() {
ExecutorService executorService = Executors.newVirtualThreadPerTaskExecutor();
return new TaskExecutorAdapter(executorService::execute);
}
@Bean
TomcatProtocolHandlerCustomizer<?> threadExecutor() {
return protocolHandler -> protocolHandler.setExecutor(
Executors.newVirtualThreadPerTaskExecutor()
);
}
}
标签:springboot,jdk,Executors,springframework,Bean,线程,org,import
From: https://www.cnblogs.com/poifa/p/17564325.html