package org.security.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author zj 2022/4/27
 * 业务线程池配置
 */
@Configuration
public class ThreadPoolConfig {

	@Bean
	public ThreadPoolTaskExecutor securityThreadPool() {
		ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
		poolTaskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
		poolTaskExecutor.setMaxPoolSize(1000);
		poolTaskExecutor.setKeepAliveSeconds(60 * 3);
		poolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		poolTaskExecutor.setThreadNamePrefix("security-htread-");
		return poolTaskExecutor;
	}
}
