Bootstrap

线程池配置类中有多个线程池的注入方式

package com.hand.foundry.config;

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

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ThreadPoolConfig {

    @Bean("offlineTaskExecutor")
    public ThreadPoolTaskExecutor executor() {
        int coreSize = Runtime.getRuntime().availableProcessors();
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(coreSize * 4);
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("async-offline-id-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
    @Bean("sendElephantExecutor")
    public ThreadPoolTaskExecutor faiExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(4);
        executor.setQueueCapacity(3000);
        executor.setThreadNamePrefix("async-elephant-id-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}

@Autowired

@Qualifier("sendElephantExecutor")

private ThreadPoolTaskExecutor poolExecutor

;