This repository was archived by the owner on Dec 26, 2024. It is now read-only.
Conversation
NANNDA3463
suggested changes
Nov 6, 2023
| while (true) { | ||
| try { | ||
| Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 1500)); | ||
| } catch (InterruptedException e) { |
Contributor
There was a problem hiding this comment.
캐치를 하고 아무것도 안할 경우
try{
~~~
} catch(Exception ignore)같은 식으로 변수명을 ignore로 명시해주곤 한다고 합니다
| @Override | ||
| public void run() { | ||
| while (true) { | ||
| this.mart.getStore(item).sell(); |
Contributor
There was a problem hiding this comment.
문제에서
- 마트에서는 생산자가 품목을 납품하기 전까지는 어떤 품목인지 알 수 없다.
라는 항목이 있는데, 이러면 마트가 어떤 품목(store)인지 item을 통해 알 수 있는 것 같습니다
|
|
||
| public void enter() { | ||
| try { | ||
| semaphore.acquire(); |
Contributor
There was a problem hiding this comment.
semaphore를 입장할 때 걸어주면 되겠네요!
배웠습니다
| } | ||
| } | ||
| System.out.println("물건 팔았습니다"); | ||
| this.consumerList.remove(0); |
Contributor
There was a problem hiding this comment.
간혹 IndexOutOfBoundsException이 일어나고 있습니다
Index를 활용한 제어는 자제해야 할 것 같습니다
아니면 동시접근 문제 일 수도 있겠네요
nueag
reviewed
Nov 6, 2023
|
|
||
| public class Consumer implements Runnable { | ||
|
|
||
| Mart mart; |
prospro1
reviewed
Nov 7, 2023
| this.consumerCount.addAndGet(-1); | ||
| System.out.println("손님 퇴장"); | ||
|
|
||
| semaphore.release(); |
Contributor
There was a problem hiding this comment.
semahpore 을 이런 식으로 사용하는 거군요! 배워갑니다!
prospro1
reviewed
Nov 7, 2023
| try { | ||
| wait(); | ||
| } catch (InterruptedException e) { | ||
| //TODO |
Contributor
There was a problem hiding this comment.
// TODO 는 다 하셨으면 지워주셔도 좋을 것 같습니다!
nueag
reviewed
Nov 7, 2023
|
|
||
| @Override | ||
| public void run() { | ||
| this.mart.getStore(this.item).enter(); |
Contributor
There was a problem hiding this comment.
getStore에서 null값을 받을 수 있는데 이 상황에 대한 예외처리도 필요한 것 같습니다.
nueag
reviewed
Nov 7, 2023
| } | ||
| } | ||
| System.out.println("물건 팔았습니다"); | ||
| this.consumerList.remove(0); |
Contributor
There was a problem hiding this comment.
물건을 판매하는 메소드인데 consumerList에서 remove가 일어나고 있어서 에러가 나는 것 같습니다..!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
No description provided.