-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProducer.java
37 lines (30 loc) · 941 Bytes
/
Producer.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
package producer_consumer;
public class Producer implements Runnable{
private String producerName ;
private StoreHouse storeHouse ;
public Producer(String producerName, StoreHouse storeHouse) {
this.producerName = producerName;
this.storeHouse = storeHouse;
}
public void setProducerName(String producerName) {
this.producerName = producerName;
}
public String getProducerName() {
return producerName;
}
@Override
public void run() {
execProcuct();
}
private void execProcuct() {
while(true){
Product pro = storeHouse.push();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
return;
}
System.out.println(getProducerName() + " produced " + pro);
}
}
}