-
Notifications
You must be signed in to change notification settings - Fork 0
Jaehyeon's Thread Code Review #40
base: main
Are you sure you want to change the base?
Conversation
while (true) { | ||
try { | ||
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 1500)); | ||
} catch (InterruptedException e) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
간혹 IndexOutOfBoundsException이 일어나고 있습니다
Index를 활용한 제어는 자제해야 할 것 같습니다
아니면 동시접근 문제 일 수도 있겠네요
There was a problem hiding this 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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
물건을 판매하는 메소드인데 consumerList에서 remove가 일어나고 있어서 에러가 나는 것 같습니다..!
No description provided.