package com.snp.batch.global.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 org.springframework.core.task.TaskExecutor; import java.util.concurrent.Executor; @Configuration @EnableAsync // 비동기 기능 활성화 public class AsyncConfig { @Bean(name = "apiLogExecutor") public Executor apiLogExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(2); // 기본 스레드 수 executor.setMaxPoolSize(5); // 최대 스레드 수 executor.setQueueCapacity(500); // 대기 큐 크기 executor.setThreadNamePrefix("ApiLogThread-"); executor.initialize(); return executor; } /** * 자동 재수집 전용 Executor. * 재수집 Job은 장시간 실행되므로 apiLogExecutor와 분리하여 별도 풀로 관리. */ @Bean(name = "autoRetryExecutor") public Executor autoRetryExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(1); // 재수집은 순차적으로 충분 executor.setMaxPoolSize(2); // 동시 최대 2개까지 허용 executor.setQueueCapacity(10); // 대기 큐 (초과 시 CallerRunsPolicy) executor.setThreadNamePrefix("AutoRetry-"); executor.initialize(); return executor; } /** * 배치 파티션 병렬 실행 전용 Executor. * ShipDetailUpdate 파티셔닝 등 배치 Step 병렬 처리에 사용. */ @Bean(name = "batchPartitionExecutor") public TaskExecutor batchPartitionExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(4); // 기본 파티션 수 executor.setMaxPoolSize(8); // 최대 파티션 수 executor.setQueueCapacity(20); // 대기 큐 executor.setThreadNamePrefix("BatchPartition-"); executor.initialize(); return executor; } }