Skip to content

Commit 95c6280

Browse files
committed
♻️ refactor: AOP, 스케쥴러 비동기 처리 시 스레드풀을 사용하도록 개선
1 parent 9bb3655 commit 95c6280

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

src/main/java/org/withtime/be/withtimebe/domain/log/dateplacelog/scheduler/DatePlaceLogScheduler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
77
import org.springframework.cache.annotation.CacheEvict;
8+
import org.springframework.scheduling.annotation.Async;
89
import org.springframework.scheduling.annotation.Scheduled;
910
import org.springframework.stereotype.Component;
1011
import org.springframework.transaction.annotation.Transactional;
@@ -25,6 +26,7 @@ public class DatePlaceLogScheduler {
2526
private final DatePlaceRepository datePlaceRepository;
2627
private final DatePlaceLogRepository datePlaceLogRepository;
2728

29+
@Async("logTaskExecutor")
2830
@Scheduled(cron = "${scheduler.logs.date-place.sync-cron}")
2931
@Transactional(readOnly = true)
3032
@CacheEvict(

src/main/java/org/withtime/be/withtimebe/domain/log/dateplacelog/service/query/DatePlaceLogQueryServiceImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ public class DatePlaceLogQueryServiceImpl implements DatePlaceLogQueryService {
2424
private final MongoTemplate mongoTemplate;
2525

2626
@Override
27-
@Cacheable(
28-
value = "date-place-log",
29-
key = "T(java.time.LocalDate).now().getYear() + '-' + " +
30-
"T(java.time.LocalDate).now().get(" + "T(java.time.temporal.WeekFields).ISO.weekOfYear()" + ") + '-' + " +
31-
"T(java.time.LocalDate).now().getDayOfWeek().getValue()",
32-
cacheManager = "redisCacheManager"
33-
)
3427
public List<DatePlaceLog> findMonthlyDatePlaceLogList() {
3528

3629
// 1. 추출할 필드 정의

src/main/java/org/withtime/be/withtimebe/domain/log/placecategorylog/aop/LogPlaceCategoryAspect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class LogPlaceCategoryAspect {
2727

2828
private final RedisTemplate<String, Object> redisTemplate;
2929

30-
@Async
30+
@Async("logTaskExecutor")
3131
@AfterReturning("@annotation(org.withtime.be.withtimebe.domain.log.placecategorylog.annotation.LogPlaceCategory)")
3232
public void logPlaceCategory(JoinPoint joinPoint) {
3333

src/main/java/org/withtime/be/withtimebe/domain/log/placecategorylog/scheduler/PlaceCategoryLogScheduler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package org.withtime.be.withtimebe.domain.log.placecategorylog.scheduler;
22

33
import java.time.LocalDate;
4-
import java.time.LocalDateTime;
54
import java.time.format.DateTimeFormatter;
65
import java.util.ArrayList;
76
import java.util.List;
87
import java.util.Map;
9-
import java.util.Optional;
108
import java.util.Set;
119
import java.util.function.Function;
1210
import java.util.stream.Collectors;
@@ -15,10 +13,9 @@
1513
import org.springframework.cache.annotation.CacheEvict;
1614
import org.springframework.data.redis.core.RedisTemplate;
1715
import org.springframework.data.redis.core.ZSetOperations;
16+
import org.springframework.scheduling.annotation.Async;
1817
import org.springframework.scheduling.annotation.Scheduled;
1918
import org.springframework.stereotype.Component;
20-
import org.withtime.be.withtimebe.domain.date.entity.PlaceCategory;
21-
import org.withtime.be.withtimebe.domain.date.repository.PlaceCategoryRepository;
2219
import org.withtime.be.withtimebe.domain.log.placecategorylog.converter.PlaceCategoryLogConverter;
2320
import org.withtime.be.withtimebe.domain.log.placecategorylog.model.PlaceCategoryLog;
2421
import org.withtime.be.withtimebe.domain.log.placecategorylog.repository.PlaceCategoryLogRepository;
@@ -35,6 +32,7 @@ public class PlaceCategoryLogScheduler {
3532
private final RedisTemplate<String, Object> redisTemplate;
3633
private final PlaceCategoryLogRepository placeCategoryLogRepository;
3734

35+
@Async("logTaskExecutor")
3836
@Scheduled(cron = "${scheduler.logs.place-category.sync-cron}")
3937
@CacheEvict(
4038
value = "place-category-log",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.withtime.be.withtimebe.global.config;
2+
3+
import java.util.concurrent.Executor;
4+
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.scheduling.annotation.EnableAsync;
8+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
9+
10+
@EnableAsync
11+
@Configuration
12+
public class AsyncConfig {
13+
14+
@Bean(name = "logTaskExecutor")
15+
public Executor logTaskExecutor() {
16+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
17+
executor.setCorePoolSize(1);
18+
executor.setMaxPoolSize(3);
19+
executor.setQueueCapacity(5);
20+
executor.setThreadNamePrefix("Executor-Log-");
21+
executor.initialize();
22+
return executor;
23+
}
24+
25+
@Bean(name = "weatherTaskExecutor")
26+
public Executor weatherTaskExecutor() {
27+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
28+
executor.setCorePoolSize(1);
29+
executor.setMaxPoolSize(3);
30+
executor.setQueueCapacity(5);
31+
executor.setThreadNamePrefix("Executor-Weather-");
32+
executor.initialize();
33+
return executor;
34+
}
35+
}

0 commit comments

Comments
 (0)