Open
Conversation
- 공유 자원인 `productDatabase`를 ConcurrentHashMap으로 구성 - compute() 메서드를 사용해 하나의 스레드만 재고 수정하도록 제한해서 원자성 보완 - 동일한 key에 대해 동시 접근 경합이 발생하면서 데이터 일관성을 유지하는 구조 - 상품명을 key로 사용해서 특정 상품만 락을 걸고 나머지는 병렬로 처리 가능
- 주문 코드 블록에 직접 락을 적용해서 동시성 관리 - 데드락이 발생하지 않도록 락 해제를 명시 - 전체 자원에 락이 걸리기 때문에 여러 상품에 대한 주문 병렬 처리 불가
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
제목(title)
ConcurrentHashMap과 ReentrantLock을 사용해 동시성 관리
작업 내용
productDatabase를 ConcurrentHashMap으로 구성이번 주차에서 고민되었던 지점이나, 어려웠던 점을 알려 주세요.
productDatabase를 각 스레드가 독립적으로 복사해서 사용하는 문제가 있었습니다. 결국 ReentrantLock을 추가로 사용해야 정확한 재고 감소가 이루어지는 것으로 확인했습니다. 제가 해당 개념을 맞게 이해한 것인지 궁금합니다.