import cn.com.flaginfo.platform.umsapp.configuration.config.AsyncLogThreadPoolConfig;
import cn.com.flaginfo.platform.umsapp.configuration.config.AsyncRedisThreadPoolConfig;
import cn.com.flaginfo.platform.umsapp.configuration.config.AsyncSSOThreadPoolConfig;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
@EnableAsync
public class AsyncTaskExecutePool {
private static final Logger logger = LoggerFactory.getLogger(AsyncTaskExecutePool.class);
@Autowired
private AsyncLogThreadPoolConfig logConfig;
@Bean(name = "asyncLogThreadPoolTaskExecutor")
public Executor asyncLogThreadPoolTaskExecutor() {
logger.info("init async log thread pool : {}", JSONObject.toJSONString(logConfig));
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(logConfig.getCorePoolSize());
executor.setMaxPoolSize(logConfig.getMaxPoolSize());
executor.setQueueCapacity(logConfig.getQueueCapacity());
executor.setKeepAliveSeconds(logConfig.getKeepAliveSeconds());
executor.setThreadNamePrefix("AsyncLogThreadPoolTaskExecutor");
//如果队列满了,则拒绝新请求
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
executor.initialize();
return executor;
}
}
SpringBoot异步线程池
最新推荐文章于 2025-03-27 16:49:51 发布