package com.shy.test4server;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.async.WebAsyncTask;
/**
* @ClassName: TestController
* @Description: TODO(这里用一句话描述这个类的作用)
* @author chengcai.shang@cmgplex.com
* @date 2018年12月7日 上午9:36:25
*
*/
@Controller
@RequestMapping("/test")
public class TestController {
/**
* 未使用HTTP异步的接口
*
* @Title: testCeilingNoAsync
* @Description: TODO(这里用一句话描述这个方法的作用)
* @date 2018年12月7日 上午9:40:57
*/
@GetMapping("/testCeilingNoAsync")
public String testCeilingNoAsync() {
return "";
}
/**
* 使用HTTP异步的接口
*
* @Title: testCeilingNoAsync
* @Description: TODO(这里用一句话描述这个方法的作用)
* @date 2018年12月7日 上午9:40:57
*/
@GetMapping("/testCeilingWithAsync")
public WebAsyncTask<String> testCeilingWithAsync() {
return new WebAsyncTask(() -> {
return "";
});
}
}
package com.shy.test4server.config;
import org.apache.catalina.Server;
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @ClassName: JettyConfig
* @Description: TODO(这里用一句话描述这个类的作用)
* @date 2018年12月7日 上午9:53:46
*
*/
@Configuration
public class JettyConfig {
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(
JettyServerCustomizer jettyServerCustomizer) {
JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
factory.addServerCustomizers(jettyServerCustomizer);
return factory;
}
@Bean
public JettyServerCustomizer jettyServerCustomizer() {
return server -> {
threadPool(server);
};
}
private void threadPool(Server server) {
// Tweak the connection config used by Jetty to handle incoming HTTP
// connections
final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
// 默认最大线程连接数200
threadPool.setMaxThreads(100);
// 默认最小线程连接数8
threadPool.setMinThreads(20);
// 默认线程最大空闲时间60000ms
threadPool.setIdleTimeout(60000);
}
}
package com.shy.test4server.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
/**
* @ClassName: SpringmvcConfig
* @Description: TODO(这里用一句话描述这个类的作用)
* @date 2018年12月7日 上午9:59:06
*
*/
@Configuration
public class SpringmvcConfig {
@Bean
public void configThreadPoll(AsyncSupportConfigurer asyncSupportConfigurer) {
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(10);
threadPool.setMaxPoolSize(400);
threadPool.setQueueCapacity(200);
threadPool.initialize();
asyncSupportConfigurer.setTaskExecutor(threadPool);
}
}