项目中使用callable 返回,释放tomcat线程 增加吞吐量
//列表查询
@ApiOperation(value = "职务、部门、工种列表", notes = "下拉框列表,职务、部门、工种列表大数据高性能")
@RequestMapping(value = "/listParatest", method = RequestMethod.GET)
public Callable
警告提醒
2019-01-24 10:58:12 920 [WARN]:
!!!
An Executor is required to handle java.util.concurrent.Callable return values.
Please, configure a TaskExecutor in the MVC config under "async support".
The SimpleAsyncTaskExecutor currently in use is not suitable under load.
-------------------------------
Request URI: '/AnRanPSLS/person/listParatest'
!!!
后参照网上资料加入以下重写方法来源:https://www.jb51.net/article/134289.htm
@Configuration
@ConfigurationProperties(prefix = "web-mvc-async")
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(60 * 1000L);
configurer.registerCallableInterceptors(timeoutInterceptor());
configurer.setTaskExecutor(threadPoolTaskExecutor());
}
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor();
t.setCorePoolSize(corePoolSize);
t.setMaxPoolSize(maxPoolSize);
t.setQueueCapacity(queueCapacity);
t.setThreadNamePrefix("WYF-Thread-");
return t;
}
}
springboot2 继承WebMvcConfigurationSupport 后自动配置失效,swagger-ui.html 无法访问,查资料后加入以下配置来源:https://blog.csdn.net/liu0bing/article/details/80826590
@Bean
LoginInterceptor localInterceptor() {
return new LoginInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/user/login")
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
发现项目中使用的entityManager 的
query2.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
NativeQueryImpl报错,自动化配置失效导致。后又查找发现不继承WebMvcConfigurationSupport,改为实现
WebMvcConfigurer接口即可,具体实现如下代码即可
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(60 * 1000L);
configurer.registerCallableInterceptors(timeoutInterceptor());
configurer.setTaskExecutor(threadPoolTaskExecutor());
}
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor();
t.setCorePoolSize(10);
t.setMaxPoolSize(100);
t.setQueueCapacity(20);
t.setThreadNamePrefix("WYF-Thread-");
return t;
}
}