Skip to content

Commit 7f70a01

Browse files
committed
[feat] 조회수 증가 낙관적 락
1 parent 3a568dc commit 7f70a01

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/com/moplus/moplus_server/domain/practiceTest/service/client/OptimisticLockPracticeTestFacade.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ public class OptimisticLockPracticeTestFacade {
1010
private final PracticeTestService practiceTestService;
1111

1212
public void updateViewCount(Long id) throws InterruptedException {
13-
while (true) {
13+
int retryCount = 0;
14+
int maxRetries = 5;
15+
16+
while (retryCount < maxRetries) {
1417
try {
1518
practiceTestService.updateViewCount(id);
16-
1719
break;
1820
} catch (Exception e) {
21+
retryCount++;
22+
if (retryCount >= maxRetries) {
23+
throw new RuntimeException("최대 재시도 횟수를 초과했습니다.", e);
24+
}
1925
Thread.sleep(50);
2026
}
2127
}
22-
2328
}
2429
}

0 commit comments

Comments
 (0)