kimi
2020-03-24 b5636e416a2fe029f96aec6ddfd3489394925b15
src/main/java/com/highdatas/mdm/util/OriginConfig.java
@@ -1,11 +1,17 @@
package com.highdatas.mdm.util;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.concurrent.Executor;
/**
 * @author kimi
@@ -14,7 +20,7 @@
 */
@Configuration
public class OriginConfig implements WebMvcConfigurer {
public class OriginConfig implements WebMvcConfigurer, AsyncConfigurer {
    @Autowired
    CommonInterceptor commonInterceptor;
@@ -30,7 +36,33 @@
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(commonInterceptor);
        interceptorRegistration.excludePathPatterns("/designer/**","/upload/**", "/process/**", "/processes/**", "/swagger-ui.html", "/webjars/**", "/swagger-resources/**", "/v2/api-docs");
        interceptorRegistration.excludePathPatterns("/designer/**","/upload/**", "/process/**", "/processes/**", "/swagger-ui.html", "/webjars/**", "/swagger-resources/**", "/v2/api-docs", "/");
    }
    @Override
    @Bean
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        //设置核心线程数
        threadPool.setCorePoolSize(10);
        //设置最大线程数
        threadPool.setMaxPoolSize(100);
        //线程池所使用的缓冲队列
        threadPool.setQueueCapacity(10);
        //等待任务在关机时完成--表明等待所有线程执行完
        threadPool.setWaitForTasksToCompleteOnShutdown(true);
        // 等待时间 (默认为0,此时立即停止),并没等待xx秒后强制停止
        threadPool.setAwaitTerminationSeconds(60);
        //  线程名称前缀
        threadPool.setThreadNamePrefix("MDM-Async-");
        // 初始化线程
        threadPool.initialize();
        return threadPool;
    }
    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }
}