From bcf9dc66018f94a4883106b87e6051a95faf2437 Mon Sep 17 00:00:00 2001 From: seulgi99 Date: Thu, 4 Jul 2024 20:28:50 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=9D=BC=20=EC=A0=84?= =?UTF-8?q?=EC=86=A1=20=EB=B9=84=EB=8F=99=EA=B8=B0=EB=A1=9C=20=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../univ/LikelionClientApplication.java | 2 -- .../email/HackathonApplyEmailContent.java | 2 +- .../likelion/univ/config/AsyncConfig.java | 23 +++++++++++++++++++ .../email/sender/azure/AzureEmailSender.java | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 likelion-core/src/main/java/likelion/univ/config/AsyncConfig.java diff --git a/likelion-client/src/main/java/likelion/univ/LikelionClientApplication.java b/likelion-client/src/main/java/likelion/univ/LikelionClientApplication.java index 22704404..a7a3a3e4 100644 --- a/likelion-client/src/main/java/likelion/univ/LikelionClientApplication.java +++ b/likelion-client/src/main/java/likelion/univ/LikelionClientApplication.java @@ -3,12 +3,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @EnableCaching @EnableScheduling -@EnableAsync @SpringBootApplication public class LikelionClientApplication { diff --git a/likelion-client/src/main/java/likelion/univ/hackathon/email/HackathonApplyEmailContent.java b/likelion-client/src/main/java/likelion/univ/hackathon/email/HackathonApplyEmailContent.java index e5af1763..ad52dffd 100644 --- a/likelion-client/src/main/java/likelion/univ/hackathon/email/HackathonApplyEmailContent.java +++ b/likelion-client/src/main/java/likelion/univ/hackathon/email/HackathonApplyEmailContent.java @@ -16,7 +16,7 @@ public final class HackathonApplyEmailContent { - + diff --git a/likelion-core/src/main/java/likelion/univ/config/AsyncConfig.java b/likelion-core/src/main/java/likelion/univ/config/AsyncConfig.java new file mode 100644 index 00000000..624fe1d2 --- /dev/null +++ b/likelion-core/src/main/java/likelion/univ/config/AsyncConfig.java @@ -0,0 +1,23 @@ +package likelion.univ.config; + +import java.util.concurrent.Executor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +@Configuration +@EnableAsync +public class AsyncConfig { + + @Bean(name = "threadPoolTaskExecutor") + public Executor threadPoolTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(5); + executor.setMaxPoolSize(30); + executor.setQueueCapacity(50); + executor.setThreadNamePrefix("LIKELION_ASYNC"); + executor.initialize(); + return executor; + } +} diff --git a/likelion-infrastructure/src/main/java/likelion/univ/email/sender/azure/AzureEmailSender.java b/likelion-infrastructure/src/main/java/likelion/univ/email/sender/azure/AzureEmailSender.java index b4eaa79a..38c6930f 100644 --- a/likelion-infrastructure/src/main/java/likelion/univ/email/sender/azure/AzureEmailSender.java +++ b/likelion-infrastructure/src/main/java/likelion/univ/email/sender/azure/AzureEmailSender.java @@ -19,6 +19,7 @@ import likelion.univ.email.sender.EmailContent; import likelion.univ.email.sender.EmailSender; import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -28,6 +29,7 @@ public class AzureEmailSender implements EmailSender { private final AzureCommunicationProperties properties; + @Async @Override public void send(EmailContent emailContent) { EmailClient emailClient = setUpEmailClient();