| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.annotation.AsyncConfigurer; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | |
| | |
| | | **/ |
| | | @Configuration |
| | | @EnableAsync |
| | | public class AsyncConfiguration { |
| | | public class AsyncConfiguration{ |
| | | @Value("${ThreadPoolTask.corePoolSize}") |
| | | Integer corePoolSize; |
| | | @Value("${ThreadPoolTask.maxPoolSize}") |
| | |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | @Bean("loginExecutor") |
| | | public Executor loginExecutor(){ |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | //配置核心线程数 |
| | | executor.setCorePoolSize(corePoolSize); |
| | | //配置最大线程数 |
| | | executor.setMaxPoolSize(maxPoolSize); |
| | | //配置队列大小 |
| | | executor.setQueueCapacity(queueCapacity); |
| | | //线程的名称前缀 |
| | | executor.setThreadNamePrefix("loginExecutor-"); |
| | | //线程活跃时间(秒) |
| | | executor.setKeepAliveSeconds(keepAliveSeconds); |
| | | //等待所有任务结束后再关闭线程池 |
| | | executor.setWaitForTasksToCompleteOnShutdown(true); |
| | | //设置拒绝策略 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | //执行初始化 |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | @Bean("guideExecutor") |
| | | public Executor guideExecutor(){ |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | @Bean("globalExecutor") |
| | | public Executor globalExecutor(){ |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | //配置核心线程数 |
| | | executor.setCorePoolSize(corePoolSize); |
| | | //配置最大线程数 |
| | | executor.setMaxPoolSize(maxPoolSize); |
| | | //配置队列大小 |
| | | executor.setQueueCapacity(queueCapacity); |
| | | //线程的名称前缀 |
| | | executor.setThreadNamePrefix("globalExecutor-"); |
| | | //线程活跃时间(秒) |
| | | executor.setKeepAliveSeconds(keepAliveSeconds); |
| | | //等待所有任务结束后再关闭线程池 |
| | | executor.setWaitForTasksToCompleteOnShutdown(true); |
| | | //设置拒绝策略 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | //执行初始化 |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | @Bean("msgExecutor") |
| | | public Executor msgExecutor(){ |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | //配置核心线程数 |
| | | executor.setCorePoolSize(corePoolSize); |
| | | //配置最大线程数 |
| | | executor.setMaxPoolSize(maxPoolSize); |
| | | //配置队列大小 |
| | | executor.setQueueCapacity(queueCapacity); |
| | | //线程的名称前缀 |
| | | executor.setThreadNamePrefix("msgExecutor-"); |
| | | //线程活跃时间(秒) |
| | | executor.setKeepAliveSeconds(keepAliveSeconds); |
| | | //等待所有任务结束后再关闭线程池 |
| | | executor.setWaitForTasksToCompleteOnShutdown(true); |
| | | //设置拒绝策略 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | //执行初始化 |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | } |