AsyncConfig.java 2.36 KB
package com.batch.config;

import java.util.concurrent.Executor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig {
	
	@Value("${thread.comm.count}")
	Integer iCommAsyncThreadCount;
	@Value("${thread.ext.count}")
	Integer iExtAsyncThreadCount;
	@Value("${thread.ai.count}")
	Integer iAiAsyncThreadCount;
	

    @Bean(name = "commAsync")
    public Executor commAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(iCommAsyncThreadCount);
        executor.setMaxPoolSize(iCommAsyncThreadCount);
        executor.setQueueCapacity(1000);
        executor.setKeepAliveSeconds(15);
        executor.setAllowCoreThreadTimeOut(true);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setThreadNamePrefix("commAsync-processor-");
        executor.initialize();
        
        return executor;
    }

	@Bean(name = "extAsync")
    public Executor extAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(iExtAsyncThreadCount);
        executor.setMaxPoolSize(iExtAsyncThreadCount);
        executor.setQueueCapacity(1000);
        executor.setKeepAliveSeconds(15);
        executor.setAllowCoreThreadTimeOut(true);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setThreadNamePrefix("extAsync-processor-");
        executor.initialize();
        
        return executor;
    }
    
	@Bean(name = "aiAsync")
    public Executor aiAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(iAiAsyncThreadCount);
        executor.setMaxPoolSize(iAiAsyncThreadCount);
        executor.setQueueCapacity(1000);
        executor.setKeepAliveSeconds(15);
        executor.setAllowCoreThreadTimeOut(true);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setThreadNamePrefix("aiAsync-processor-");
        executor.initialize();
        
        return executor;
    }
}