package com.puhui.goosecard.web.config;
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;
/**
* 未考虑cpu负载情况下
*/
@Configuration
@EnableAsync
public class ExecutorConfig {
/** Set the ThreadPoolExecutor's core pool size. */
/**
* 每秒100-1000个请求,每个任务平均0.6s,每个线程每秒处理1/0.6个请求。线程范围:100/(1/0.6)-1000/(1/0.6) 60-600
*/
private int corePoolSize = 60;
/** Set the ThreadPoolExecutor's maximum pool size. */
/**
* (最大请求数-queuecapacity)/每个线程每秒处理多少任务
*/
private int maxPoolSize = 480;
/** Set the capacity for the ThreadPoolExecutor's BlockingQueue. */
/**
* (corePoolSize/tasktime)*responsetime 2s
*/
private int queueCapacity = 200;
@Bean
public Executor myAsync() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("BigGooseExecutor-");
executor.initialize();
return executor;
}
}
线程池配置例子
猜你喜欢
转载自blog.csdn.net/hanruikai/article/details/80663203
今日推荐
周排行