diff --git a/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java b/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java index e80c9fd..41669f4 100644 --- a/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java +++ b/backend/src/main/java/com/edufocus/edufocus/EdufocusApplication.java @@ -3,7 +3,9 @@ package com.edufocus.edufocus; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableAsync; +@EnableAsync @EnableJpaAuditing @SpringBootApplication public class EdufocusApplication { diff --git a/backend/src/main/java/com/edufocus/edufocus/global/config/AsyncConfig.java b/backend/src/main/java/com/edufocus/edufocus/global/config/AsyncConfig.java new file mode 100644 index 0000000..4a2cee9 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/global/config/AsyncConfig.java @@ -0,0 +1,32 @@ +package com.edufocus.edufocus.global.config; + +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.AsyncConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +import java.util.concurrent.Executor; + +@Configuration +@EnableWebMvc +public class AsyncConfig implements AsyncConfigurer { + + @Override + @Bean(name = "mailExecutor") + public Executor getAsyncExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(5); + executor.setMaxPoolSize(10); + executor.setQueueCapacity(500); + executor.setThreadNamePrefix("MailExecutor-"); + executor.initialize(); + return executor; + } + + @Override + public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + return AsyncConfigurer.super.getAsyncUncaughtExceptionHandler(); + } +} diff --git a/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java index 201c99d..a5c1eb9 100644 --- a/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java @@ -8,6 +8,7 @@ import lombok.ToString; import lombok.extern.slf4j.Slf4j; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.util.Random; @@ -27,6 +28,7 @@ public class MailServiceImpl implements MailService { private final RedisUtil redisUtil; @Override + @Async("mailExecutor") public void sendMail(String email) { String code = createRandomCode();