-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConsumer.java
38 lines (30 loc) · 961 Bytes
/
Consumer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package producer_consumer;
public class Consumer implements Runnable{
private String consumerName = null;
private StoreHouse storeHouse = null;
public Consumer(String consumerName, StoreHouse storeHouse) {
this.consumerName = consumerName;
this.storeHouse = storeHouse;
}
public void setConsumerName(String consumerName) {
this.consumerName = consumerName;
}
public String getConsumerName() {
return consumerName;
}
public void execConsume() {
while (true) {
Product pro = storeHouse.pop();
try {
Thread.sleep(400);
} catch (InterruptedException e) {
return;
}
System.out.println(getConsumerName() + " consumed " + pro);
}
}
@Override
public void run() {
execConsume();
}
}