From 96dd033be97dbaca0d43b03f24b0e7b7d35d25d6 Mon Sep 17 00:00:00 2001 From: yb__char Date: Fri, 13 Dec 2024 15:22:53 +0900 Subject: [PATCH] refactor: ThreadConfig --- .../global/config/thread/ThreadConfig.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/com/depromeet/global/config/thread/ThreadConfig.java 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()); + } +}