// Given
log.info("makeReservation 동시성 테스트 준비");
int numberOfThreads = 5;
ExecutorService service = Executors.newFixedThreadPool(numberOfThreads);
CountDownLatch latch = new CountDownLatch(numberOfThreads);
// When
log.info("makeReservation 동시성 테스트 진행");
service.execute(() -> {
System.out.println(LocalDateTime.now());
log.info("approvalTxId 검사-1 Response : {}", redisService.keyLock(repeatCheckRequest));
latch.countDown();
});
service.execute(() -> {
System.out.println(LocalDateTime.now());
log.info("approvalTxId 검사-1 Response : {}", redisService.keyLock(repeatCheckRequest));
latch.countDown();
});
service.execute(() -> {
System.out.println(LocalDateTime.now());
log.info("approvalTxId 검사-1 Response : {}", redisService.keyLock(repeatCheckRequest));
latch.countDown();
});
service.execute(() -> {
System.out.println(LocalDateTime.now());
log.info("approvalTxId 검사-1 Response : {}", redisService.keyLock(repeatCheckRequest));
latch.countDown();
});
service.execute(() -> {
System.out.println(LocalDateTime.now());
log.info("approvalTxId 검사-1 Response : {}", redisService.keyLock(repeatCheckRequest));
latch.countDown();
});
latch.await();
int numberOfThreads = 5;
ExecutorService service = Executors.newFixedThreadPool(numberOfThreads);
CountDownLatch latch = new CountDownLatch(numberOfThreads);
service.execute(() -> {
System.out.println("1번 스레드 : " + LocalDateTime.now());
try {
checkApprovalTxId(redisKey);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
latch.countDown();
});
service.execute(() -> {
System.out.println("2번 스레드 : " + LocalDateTime.now());
try {
checkApprovalTxId(redisKey);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
latch.countDown();
});
'백앤드 이야기 > JAVA&Spring' 카테고리의 다른 글
[Spring] HttpSessionListener 이용해 동시 로그인 사용자 및 세션 관리 (2) | 2024.03.12 |
---|---|
[JAVA] Checked Exception, Unchecked Exception (0) | 2023.12.14 |
[JAVA] URL query parsing, 주소 파라메터 파싱 (0) | 2023.11.16 |
[JAVA] 자바로 셀레니움(Selenium)을 구현해보자!(크롤링) (0) | 2023.10.28 |
[JAVA] 이름 규칙 (0) | 2023.07.22 |
댓글