Skip to content

Commit

Permalink
[#28] feat: 비동기 방식 SimpleAsyncTaskExecutor에서 TaskExecutor로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeuk520 committed Sep 5, 2024
1 parent 32f5582 commit e30da06
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/ku/covigator/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
package com.ku.covigator.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;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
@EnableAsync
public class AsyncConfig {

private static final int CORE_POOL_SIZE = 30;
private static final int MAX_POOL_SIZE = 50;
private static final int QUEUE_CAPACITY = 100;
private static final boolean WAIT_TASK_COMPLETE = true;
private static final int AWAIT_TERMINATION_SECONDS = 30;

@Bean(name = "threadPoolTaskExecutor")
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(CORE_POOL_SIZE);
taskExecutor.setMaxPoolSize(MAX_POOL_SIZE);
taskExecutor.setQueueCapacity(QUEUE_CAPACITY);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
taskExecutor.setWaitForTasksToCompleteOnShutdown(WAIT_TASK_COMPLETE);
taskExecutor.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
taskExecutor.initialize();
return taskExecutor;
}
}

0 comments on commit e30da06

Please sign in to comment.