2026-05-09 21:29:18 +09:00
|
|
|
package com.ga.common.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 java.util.concurrent.Executor;
|
|
|
|
|
|
2026-06-12 23:40:28 +09:00
|
|
|
/**
|
|
|
|
|
* 비동기 실행 설정. @Async 가 붙은 메서드를 별도 스레드 풀에서 돌리기 위한 구성.
|
|
|
|
|
*
|
|
|
|
|
* <p>왜 필요한가: API 접근 로그 저장({@code saveAsync}) 같은 부가 작업은 본 요청 응답을 느리게 하면 안 된다.
|
|
|
|
|
* @EnableAsync 로 비동기 기능을 켜고, 전용 스레드 풀(asyncExecutor)을 정의해 부가 작업을 백그라운드로 넘긴다.
|
|
|
|
|
*/
|
2026-05-09 21:29:18 +09:00
|
|
|
@Configuration
|
|
|
|
|
@EnableAsync
|
|
|
|
|
public class AsyncConfig {
|
|
|
|
|
|
2026-06-12 23:40:28 +09:00
|
|
|
// @Async("asyncExecutor") 로 지정해 사용하는 전용 스레드 풀.
|
2026-05-09 21:29:18 +09:00
|
|
|
@Bean(name = "asyncExecutor")
|
|
|
|
|
public Executor asyncExecutor() {
|
|
|
|
|
ThreadPoolTaskExecutor ex = new ThreadPoolTaskExecutor();
|
2026-06-12 23:40:28 +09:00
|
|
|
ex.setCorePoolSize(4); // 기본 유지 스레드 수
|
|
|
|
|
ex.setMaxPoolSize(16); // 큐가 가득 찰 때 늘릴 수 있는 최대 스레드 수
|
|
|
|
|
ex.setQueueCapacity(500); // 대기 작업 큐 크기(초과분이 생기면 maxPool까지 확장)
|
|
|
|
|
ex.setThreadNamePrefix("ga-async-"); // 로그에서 비동기 스레드를 알아보기 쉽게 이름 접두어 지정
|
2026-05-09 21:29:18 +09:00
|
|
|
ex.initialize();
|
|
|
|
|
return ex;
|
|
|
|
|
}
|
|
|
|
|
}
|