-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#28] feat: 비동기 방식 SimpleAsyncTaskExecutor에서 TaskExecutor로 변경
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |