-
Notifications
You must be signed in to change notification settings - Fork 0
Feat Thread exam and assignment #41
base: main
Are you sure you want to change the base?
Conversation
public void run() { | ||
getBuyItem(); | ||
mart.enterStore(buyItem); | ||
while (!isCheck.get()) { |
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.
wait으로 기다리는데
while (!isCheck.get()) {
이 있어야 할까용
mart.exitStore(buyItem); | ||
} | ||
|
||
public void getBuyItem() { |
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.
여기에서만 사용한다면 private 접근 제어자를 사용하거나 랜덤한 값을 리턴하는 메서드면 더 좋겠습니다
thread.interrupt(); | ||
} | ||
|
||
public void join() throws InterruptedException { |
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.
사용하지 않는 메서드들은 지워줘도 좋을 것 같습니다
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.
추후에 사용할 수 있기 때문에 join을 만들었습니다!
@@ -0,0 +1,15 @@ | |||
package com.nhnacademy.parkminsu.assignment; | |||
|
|||
public enum Items { |
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.
이 enum은 사용처가 없습니다
지우거나 활용하면 좋은 코드가 될 것 같습니다
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.
맞네요 enum을 구현했는데 활용을 하지 않았네요
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.
수정했습니다
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 10000)); | ||
store.sell(); | ||
System.out.println(thread.getName() + "가 구매했습니다"); | ||
isCheck.set(true); |
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.
이런 흐름이라면 isCehck가 필요 없을 것 같습니다
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.
수정했습니다!
* 매장에서 물건이 들어오면 소비자에게 알려줌 | ||
*/ | ||
public class Store { | ||
AtomicInteger consumerCount; |
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.
접근제어자가 필요할 것 같습니다
|
||
|
||
public Consumer(String name, Store store) { | ||
thread = new Thread(this, name); |
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 키워드를 안써준 이유가 있을까요??
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.
수정했습니다!
@@ -0,0 +1,15 @@ | |||
package com.nhnacademy.parkminsu.assignment; | |||
|
|||
public enum Items { |
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.
맞네요 enum을 구현했는데 활용을 하지 않았네요
No description provided.