Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Conversation

hyeonjaez
Copy link
Member

No description provided.

while (true) {
try {
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 1500));
} catch (InterruptedException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

캐치를 하고 아무것도 안할 경우

try{
        ~~~
} catch(Exception ignore)

같은 식으로 변수명을 ignore로 명시해주곤 한다고 합니다

@Override
public void run() {
while (true) {
this.mart.getStore(item).sell();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제에서

  • 마트에서는 생산자가 품목을 납품하기 전까지는 어떤 품목인지 알 수 없다.

라는 항목이 있는데, 이러면 마트가 어떤 품목(store)인지 item을 통해 알 수 있는 것 같습니다


public void enter() {
try {
semaphore.acquire();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semaphore를 입장할 때 걸어주면 되겠네요!
배웠습니다

}
}
System.out.println("물건 팔았습니다");
this.consumerList.remove(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간혹 IndexOutOfBoundsException이 일어나고 있습니다
Index를 활용한 제어는 자제해야 할 것 같습니다
아니면 동시접근 문제 일 수도 있겠네요

Copy link
Contributor

@minsu11 minsu11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parkminsu code review


public class Consumer implements Runnable {

Mart mart;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

접근제어자 빠졌습니당

this.consumerCount.addAndGet(-1);
System.out.println("손님 퇴장");

semaphore.release();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semahpore 을 이런 식으로 사용하는 거군요! 배워갑니다!

try {
wait();
} catch (InterruptedException e) {
//TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO 는 다 하셨으면 지워주셔도 좋을 것 같습니다!


@Override
public void run() {
this.mart.getStore(this.item).enter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStore에서 null값을 받을 수 있는데 이 상황에 대한 예외처리도 필요한 것 같습니다.

}
}
System.out.println("물건 팔았습니다");
this.consumerList.remove(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

물건을 판매하는 메소드인데 consumerList에서 remove가 일어나고 있어서 에러가 나는 것 같습니다..!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants