默认情况下,spring web flux使用netty,它是单线程事件循环。如何配置spring boot以便为每个核心创建一个线程。
谢谢,
LOKESH
答案 0 :(得分:5)
如Spring Boot reference documentation所述,您可以使用@Component
public class MyNettyWebServerCustomizer
implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
@Override
public void customize(NettyReactiveWebServerFactory factory) {
factory.addServerCustomizers(new EventLoopNettyCustomizer());
}
}
class EventLoopNettyCustomizer implements NettyServerCustomizer {
@Override
public HttpServer apply(HttpServer httpServer) {
EventLoopGroup eventLoopGroup = //...;
return httpServer.tcpConfiguration(tcpServer ->
tcpServer.bootstrap(serverBootstrap
-> serverBootstrap.group(eventLoopGroup)));
}
}
自定义Reactor Netty Web服务器。
这是Spring Boot 2.1的一个例子:
sum
答案 1 :(得分:-3)
您可以更改依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html