snp-batch-validation/src/main/java/com/snp/batch/global/config/AsyncConfig.java
HYOJIN 59ecdd851e feat(shipdetail): 선박제원정보 배치 작업 병렬화 (Partitioned Step)
- IMO 목록을 N개 파티션으로 분할하여 병렬 API 호출
- ImoFetchTasklet으로 IMO 조회 단계 분리
- sourceStepExecutionId → sourceJobExecutionId 마이그레이션
- afterFetch 중복 실행 방지 플래그 추가
- partition-count 설정 외부화 (dev:2, prod:4)
2026-03-20 16:15:05 +09:00

56 lines
2.2 KiB
Java

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;
}
}