SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);这样设置的话很不安全,不废话,直接上代码,改造一下AsyncConfig就可以了,线程也安全
/** * @description: 线程池的配置 */ @Configuration public class AsyncConfig { private static final int MAX_POOL_SIZE = 50; private static final int CORE_POOL_SIZE = 20; @Bean("MisTaskExecutor") public TaskExecutor MisTaskExecutor() { ThreadPoolTaskExecutor asyncTaskExecutor = new ThreadPoolTaskExecutor(); // 设置核心线程数 asyncTaskExecutor.setCorePoolSize(CORE_POOL_SIZE); // 设置最大线程数 asyncTaskExecutor.setMaxPoolSize(MAX_POOL_SIZE); // 设置队列容量 asyncTaskExecutor.setQueueCapacity(20); // 设置线程活跃时间(秒) asyncTaskExecutor.setKeepAliveSeconds(60); // 设置默认线程名称 asyncTaskExecutor.setThreadNamePrefix("Mis-Async"); // 设置拒绝策略 asyncTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 等待所有任务结束后再关闭线程池 asyncTaskExecutor.setWaitForTasksToCompleteOnShutdown(true); asyncTaskExecutor.initialize(); //这句很关键 return new DelegatingSecurityContextAsyncTaskExecutor(asyncTaskExecutor); //这句也很关键 } }
标签:设置,SpringBoot,asyncTaskExecutor,线程,Context,new,Async,POOL,SIZE From: https://www.cnblogs.com/kakaeex/p/17705403.html