-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from FinalDoubleTen/BE-68-Async-Trip-Path
Refactor : 경로 계산 컴포넌트 비동기적으로 호출
- Loading branch information
Showing
3 changed files
with
58 additions
and
23 deletions.
There are no files selected for viewing
12 changes: 11 additions & 1 deletion
12
src/main/java/org/tenten/tentenstomp/config/AsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
package org.tenten.tentenstomp.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
@Configuration | ||
public class AsyncConfig { | ||
|
||
@Bean | ||
public Executor myPool() { | ||
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); | ||
threadPoolTaskExecutor.setCorePoolSize(5); // 기본 스레드 수 | ||
threadPoolTaskExecutor.setMaxPoolSize(20); // 최대 스레드 수 | ||
return threadPoolTaskExecutor; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/tenten/tentenstomp/global/component/AsyncPathComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.tenten.tentenstomp.global.component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.tenten.tentenstomp.domain.trip.dto.response.TripPathInfoMsg; | ||
import org.tenten.tentenstomp.global.component.dto.request.TripPlace; | ||
|
||
import java.util.List; | ||
|
||
import static org.tenten.tentenstomp.global.common.enums.Transportation.CAR; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class AsyncPathComponent { | ||
private final OdsayComponent odsayComponent; | ||
private final NaverMapComponent naverMapComponent; | ||
@Async | ||
public void calculatePath(TripPlace fromPlace, TripPlace toPlace, List<TripPathInfoMsg> pathInfoMsgs) { | ||
|
||
long startTime = System.currentTimeMillis(); | ||
TripPathInfoMsg.PathInfo pathInfo; | ||
if (toPlace.transportation().equals(CAR)) { | ||
pathInfo = naverMapComponent.calculatePathInfo(fromPlace.longitude(), fromPlace.latitude(), toPlace.longitude(), toPlace.latitude()); | ||
} else { | ||
pathInfo = odsayComponent.calculatePathInfo(fromPlace.longitude(), fromPlace.latitude(), toPlace.longitude(), toPlace.latitude()); | ||
} | ||
log.info("from " + fromPlace.seqNum() + " to " + toPlace.seqNum() + " executionTime : " + ((System.currentTimeMillis() - startTime) / 1000.0)); | ||
pathInfoMsgs.add(new TripPathInfoMsg(fromPlace.seqNum(), toPlace.seqNum(), fromPlace.longitude(), fromPlace.latitude(), toPlace.longitude(), toPlace.latitude(), toPlace.transportation(), pathInfo)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters