首页>代码>Spring Boot+Mybatis+thymeleaf开发的高仿今日头条新闻网站>/src/main/java/com/lm/cms2/comment/task/BeanConfig.java
package com.lm.cms2.comment.task;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@EnableAsync
public class BeanConfig {
@Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 设置核心线程数
executor.setCorePoolSize(5);
// 设置最大线程数
executor.setMaxPoolSize(10);
// 设置队列容量
executor.setQueueCapacity(20);
// 设置线程活跃时间(秒)
executor.setKeepAliveSeconds(60);
// 设置默认线程名称
executor.setThreadNamePrefix("hello-");
// 设置拒绝策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 等待所有任务结束后再关闭线程池
executor.setWaitForTasksToCompleteOnShutdown(true);
return executor;
}
}
最近下载更多
微信网友_6927932988952576 LV12
2024年3月31日
admin_z LV22
2024年2月4日
chenlie LV2
2023年11月7日
zzzzzzzzhasdas LV13
2023年9月6日
mq13947193109 LV19
2023年8月1日
1806795436 LV4
2023年1月10日
微信网友_6257235205754880 LV1
2022年12月11日
huyuxin LV4
2022年11月9日
hdell65 LV6
2022年10月7日
Ohh. LV3
2022年5月17日
最近浏览更多
zhouweizhan
3月28日
暂无贡献等级
zolscy LV24
2024年11月29日
微信网友_7134912998903808 LV15
2024年8月29日
f22m1a2b2 LV17
2024年5月30日
来一杯西瓜冰咩 LV6
2024年5月13日
forgetmenot LV1
2024年4月25日
微信网友_6927932988952576 LV12
2024年3月31日
admin_z LV22
2024年1月28日
fff2003 LV9
2023年11月17日
wnnmmb LV2
2023年11月13日

