1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Fix WebServerContainerConfigure

This commit is contained in:
dengchao@xgtl 2020-04-15 17:24:43 +08:00
parent 13fe10e231
commit 33b41ed395
2 changed files with 67 additions and 69 deletions

View File

@ -375,6 +375,13 @@
<artifactId>sdk</artifactId> <artifactId>sdk</artifactId>
<version>2.1.0</version> <version>2.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -16,52 +16,43 @@
*/ */
package com.chatopera.cc.config; package com.chatopera.cc.config;
import lombok.RequiredArgsConstructor;
import org.apache.catalina.connector.Connector; import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol; import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer; import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
@Configuration @Configuration
public class WebServerContainerConfigure { public class WebServerContainerConfigure {
@Value("${server.threads.max}") @Value("${server.threads.max}")
private Integer maxthread; private Integer maxThread;
@Value("${server.connection.max}") @Value("${server.connection.max}")
private Integer maxconnections; private Integer maxConnections;
@Value("${web.upload-path}")
private String path;
@Bean @Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() throws IOException, NoSuchAlgorithmException { public ConfigurableTomcatWebServerFactory createEmbeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory(); ConfigurableTomcatWebServerFactory tomcatFactory = new TomcatServletWebServerFactory();
tomcatFactory.addConnectorCustomizers(new CSKeFuTomcatConnectorCustomizer(maxthread, maxconnections)); tomcatFactory.addConnectorCustomizers(new CSKeFuTomcatConnectorCustomizer(maxThread, maxConnections));
return tomcatFactory; return tomcatFactory;
} }
class CSKeFuTomcatConnectorCustomizer implements TomcatConnectorCustomizer { @RequiredArgsConstructor
private Integer maxthread; private static class CSKeFuTomcatConnectorCustomizer implements TomcatConnectorCustomizer {
private Integer maxconnection; private final Integer maxThread;
private final Integer maxConnection;
CSKeFuTomcatConnectorCustomizer(Integer maxthread, Integer maxconnection) {
this.maxthread = maxthread;
this.maxconnection = maxconnection;
}
public void customize(Connector connector) { public void customize(Connector connector) {
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
//设置最大连接数 //设置最大连接数
protocol.setMaxConnections(maxthread != null ? maxthread : 2000); protocol.setMaxConnections(maxThread != null ? maxThread : 2000);
//设置最大线程数 //设置最大线程数
protocol.setMaxThreads(maxconnection != null ? maxconnection : 2000); protocol.setMaxThreads(maxConnection != null ? maxConnection : 2000);
protocol.setConnectionTimeout(30000); protocol.setConnectionTimeout(30000);
} }
} }