com.gitee.fufu669.config.ThreadPoolTaskExecutorConfig Maven / Gradle / Ivy
package com.gitee.fufu669.config;
import com.gitee.fufu669.config.redis.ShardedJedisPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
/** @author wangfupeng */
@ComponentScan(basePackages = {"com.gitee.fufu669"})
public class ThreadPoolTaskExecutorConfig {
private static final Logger logger = LoggerFactory.getLogger(ThreadPoolTaskExecutorConfig.class);
@Value("${threadpooltaskexecutor.corepoolsize}")
private String corepoolsize;
@Value("${threadpooltaskexecutor.maxpoolsize}")
private String maxpoolsize;
@Value("${threadpooltaskexecutor.queuecapacity}")
private String queuecapacity;
@Value("${threadpooltaskexecutor.keepaliveseconds}")
private String keepaliveseconds;
@Value("${threadpooltaskexecutor.threadnameprefix}")
private String threadnameprefix;
@Bean(name="threadPoolTaskExecutorCacheFetchLater")
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(Integer.valueOf(corepoolsize));
executor.setMaxPoolSize(Integer.valueOf(maxpoolsize));
executor.setQueueCapacity(Integer.valueOf(queuecapacity));
executor.setKeepAliveSeconds(Integer.valueOf(keepaliveseconds));
executor.setThreadNamePrefix(threadnameprefix);
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
}