线程池注入:
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;
import java.util.concurrent.ThreadPoolExecutor;
/** @Auther: Administrator @Date: 2020/3/31 11:56 @Description: AsyncConfig @Version 1.0 */
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {
@Bean("defaultThreadPool")
public ThreadPoolTaskExecutor defaultThreadPool() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数目
executor.setCorePoolSize(5);
// 指定最大线程数
executor.setMaxPool
本文介绍了如何使用线程池进行异步数据插入,当核心线程不足以处理任务时,线程池会自动扩展。通过接口传递值并提交任务,而不是启动线程。同时,文章还提到了如何进行线程池状态的定时监控,以观察线程池的工作情况。
订阅专栏 解锁全文
1852

被折叠的 条评论
为什么被折叠?



