Skip to content

Commit

Permalink
Merge pull request #52 from Kusitms-POPTATO-DEV/refactor/async-scheduler
Browse files Browse the repository at this point in the history
Refactor: scheduler async 비동기 처리
  • Loading branch information
pkl0912 authored Nov 26, 2024
2 parents bc671b0 + 37b4499 commit 3ee76db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/main/java/server/poptato/global/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package server.poptato.global.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{

@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

executor.setCorePoolSize(10);
executor.setMaxPoolSize(20);
executor.setQueueCapacity(15000);

executor.setThreadNamePrefix("Async-Executor-");

executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());

executor.initialize();
return executor;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import server.poptato.external.firebase.service.FCMService;
Expand Down Expand Up @@ -37,7 +38,7 @@ public void updateTodoType() {
updateTodo(updatedTodoIds);
sendDeadlineNotifications();
}

@Async
public void updateTodo(List<Long> updatedTodoIds) {
Map<Long, List<Todo>> userIdAndTodaysMap = updateTodays(updatedTodoIds);
List<Todo> yesterdayTodos = updateYesterdays(updatedTodoIds);
Expand Down Expand Up @@ -97,7 +98,7 @@ private void save(Map<Long, List<Todo>> userIdAndTodaysMap, List<Todo> yesterday
todoRepository.save(todo);
}
}

@Async
public void sendDeadlineNotifications() {
List<User> users = userRepository.findAll();

Expand Down

0 comments on commit 3ee76db

Please sign in to comment.