diff --git a/src/main/java/com/depromeet/global/config/thread/ThreadConfig.java b/src/main/java/com/depromeet/global/config/thread/ThreadConfig.java new file mode 100644 index 00000000..54c0c5c1 --- /dev/null +++ b/src/main/java/com/depromeet/global/config/thread/ThreadConfig.java @@ -0,0 +1,24 @@ +package com.depromeet.global.config.thread; + +import java.util.concurrent.Executors; +import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; +import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.AsyncTaskExecutor; +import org.springframework.core.task.support.TaskExecutorAdapter; + +@Configuration +public class ThreadConfig { + + @Bean(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME) + public AsyncTaskExecutor asyncTaskExecutor() { + return new TaskExecutorAdapter(Executors.newVirtualThreadPerTaskExecutor()); + } + + @Bean + public TomcatProtocolHandlerCustomizer protocolHandlerVirtualThreadExecutorCustomizer() { + return protocolHandler -> + protocolHandler.setExecutor(Executors.newVirtualThreadPerTaskExecutor()); + } +}